dataverse-utils 4.0.1 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -11
- package/README.md +0 -24
- package/lib/assemblyDeploy.js +0 -57
- package/lib/auth.js +0 -75
- package/lib/cachePlugin.js +0 -107
- package/lib/dataverse.service.js +0 -71
- package/lib/deploy.js +0 -74
- package/lib/generate.js +0 -103
- package/lib/index.js +0 -44
- package/lib/logger.js +0 -37
- package/lib/models/customApi.js +0 -77
- package/lib/models/pluginAssembly.js +0 -88
- package/lib/models/pluginImage.js +0 -68
- package/lib/models/pluginPackage.js +0 -93
- package/lib/models/pluginStep.js +0 -97
- package/lib/models/pluginType.js +0 -67
- package/lib/models/webResource.js +0 -133
- package/lib/webResourceDeploy.js +0 -31
- package/license +0 -21
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataverse-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Utilities for interacting with Dataverse environments",
|
|
6
|
-
"
|
|
6
|
+
"exports": "./lib/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"dataverse-utils": "lib/index.js"
|
|
9
9
|
},
|
|
10
10
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
11
|
+
"node": ">=20.0.0"
|
|
12
12
|
},
|
|
13
|
+
"type": "module",
|
|
13
14
|
"files": [
|
|
14
15
|
"/lib"
|
|
15
16
|
],
|
|
@@ -24,19 +25,18 @@
|
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"@azure/msal-node": "^2.10.0",
|
|
27
|
-
"commander": "^
|
|
28
|
-
"cryptr": "^6.
|
|
29
|
-
"dataverse-webapi": "^
|
|
30
|
-
"figures": "^
|
|
31
|
-
"glob": "^
|
|
28
|
+
"commander": "^13.1.0",
|
|
29
|
+
"cryptr": "^6.3.0",
|
|
30
|
+
"dataverse-webapi": "^3.0.0",
|
|
31
|
+
"figures": "^6.1.0",
|
|
32
|
+
"glob": "^11.0.1",
|
|
32
33
|
"kleur": "^4.1.5",
|
|
33
34
|
"prompts": "^2.4.2"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"@types/cryptr": "^4.0.
|
|
37
|
+
"@types/cryptr": "^4.0.3",
|
|
37
38
|
"@types/glob": "^8.1.0",
|
|
38
|
-
"@types/
|
|
39
|
-
"@types/prompts": "^2.4.4"
|
|
39
|
+
"@types/prompts": "^2.4.9"
|
|
40
40
|
},
|
|
41
41
|
"volta": {
|
|
42
42
|
"extends": "../../package.json"
|
package/README.md
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# dataverse-utils
|
|
2
|
-
| NPM |
|
|
3
|
-
| --- |
|
|
4
|
-
| [](https://www.npmjs.com/package/dataverse-utils) |
|
|
5
|
-
|
|
6
|
-
Utilities for interacting with Dataverse environments
|
|
7
|
-
|
|
8
|
-
# Deploy
|
|
9
|
-
|
|
10
|
-
Deployment configuration is stored in dataverse.config.json. Access token will be acquired via device-code flow.
|
|
11
|
-
|
|
12
|
-
```sh
|
|
13
|
-
dataverse-utils deploy webresource
|
|
14
|
-
|
|
15
|
-
dataverse-utils deploy assembly
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
# Generate Early-Bound TS Files
|
|
19
|
-
|
|
20
|
-
Generate early bound TypeScript files for tables. Access token will be acquired via device-code flow.
|
|
21
|
-
|
|
22
|
-
```sh
|
|
23
|
-
dataverse-utils generate account
|
|
24
|
-
```
|
package/lib/assemblyDeploy.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.assemblyDeploy = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const pluginAssembly_1 = require("./models/pluginAssembly");
|
|
10
|
-
const pluginPackage_1 = require("./models/pluginPackage");
|
|
11
|
-
const customApi_1 = require("./models/customApi");
|
|
12
|
-
const logger_1 = require("./logger");
|
|
13
|
-
async function assemblyDeploy(creds, apiConfig) {
|
|
14
|
-
const currentPath = '.';
|
|
15
|
-
const configFile = await fs_1.default.promises.readFile(path_1.default.resolve(currentPath, 'dataverse.config.json'), 'utf8');
|
|
16
|
-
if (configFile == null) {
|
|
17
|
-
logger_1.logger.warn('unable to find dataverse.config.json file');
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const config = JSON.parse(configFile);
|
|
21
|
-
if (config.assembly) {
|
|
22
|
-
logger_1.logger.info('deploy plugin package');
|
|
23
|
-
try {
|
|
24
|
-
await (0, pluginPackage_1.deployPluginPackage)(config, apiConfig, creds.solution);
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
logger_1.logger.error(error.message);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
logger_1.logger.done(`deployed plugin package ${config.prefix}_${config.name}\r\n`);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
logger_1.logger.info(`deploy assembly to ${creds.server}`);
|
|
34
|
-
try {
|
|
35
|
-
await (0, pluginAssembly_1.deployAssembly)(config, apiConfig, creds.solution);
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
logger_1.logger.error(error.message);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
logger_1.logger.done(`deployed assembly ${config.name}`);
|
|
42
|
-
}
|
|
43
|
-
if (config.customapis?.length > 0 && (config.pluginassemblyid || config.assembly?.pluginassemblyid)) {
|
|
44
|
-
logger_1.logger.info('deploy custom api');
|
|
45
|
-
const assemblyId = config.pluginassemblyid ?? config.assembly.pluginassemblyid;
|
|
46
|
-
try {
|
|
47
|
-
const promises = config.customapis.map((a) => (0, customApi_1.deployApi)(a, assemblyId, apiConfig, creds.solution));
|
|
48
|
-
await Promise.all(promises);
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
logger_1.logger.error(error.message);
|
|
52
|
-
}
|
|
53
|
-
logger_1.logger.done('deployed custom api');
|
|
54
|
-
}
|
|
55
|
-
await fs_1.default.promises.writeFile(path_1.default.resolve(currentPath, 'dataverse.config.json'), JSON.stringify(config, null, 4), 'utf8');
|
|
56
|
-
}
|
|
57
|
-
exports.assemblyDeploy = assemblyDeploy;
|
package/lib/auth.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getAccessToken = exports.onTokenFailure = void 0;
|
|
7
|
-
const prompts_1 = __importDefault(require("prompts"));
|
|
8
|
-
const cachePlugin_1 = require("./cachePlugin");
|
|
9
|
-
const msal_node_1 = require("@azure/msal-node");
|
|
10
|
-
const logger_1 = require("./logger");
|
|
11
|
-
const clientId = '51f81489-12ee-4a9e-aaae-a2591f45987d';
|
|
12
|
-
const onTokenFailure = async (url, error) => {
|
|
13
|
-
if (error) {
|
|
14
|
-
logger_1.logger.error(`failed to acquire access token: ${error}`);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
logger_1.logger.error('failed to acquire access token');
|
|
18
|
-
}
|
|
19
|
-
if ((0, cachePlugin_1.cacheExists)(url)) {
|
|
20
|
-
const { deleteToken } = await (0, prompts_1.default)({
|
|
21
|
-
type: 'confirm',
|
|
22
|
-
name: 'deleteToken',
|
|
23
|
-
message: `delete current token cache for ${url}?`
|
|
24
|
-
});
|
|
25
|
-
if (deleteToken) {
|
|
26
|
-
(0, cachePlugin_1.deleteCache)(url);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
exports.onTokenFailure = onTokenFailure;
|
|
31
|
-
const getAccessToken = async (authEndpoint, url) => {
|
|
32
|
-
const config = {
|
|
33
|
-
auth: {
|
|
34
|
-
clientId: clientId,
|
|
35
|
-
authority: authEndpoint
|
|
36
|
-
},
|
|
37
|
-
cache: {
|
|
38
|
-
cachePlugin: (0, cachePlugin_1.cachePlugin)(url)
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const pca = new msal_node_1.PublicClientApplication(config);
|
|
42
|
-
const cache = pca.getTokenCache();
|
|
43
|
-
const accounts = await cache?.getAllAccounts().catch(ex => {
|
|
44
|
-
throw new Error(ex.message);
|
|
45
|
-
});
|
|
46
|
-
// Try to get token silently
|
|
47
|
-
if (accounts.length > 0) {
|
|
48
|
-
try {
|
|
49
|
-
const silentToken = await pca.acquireTokenSilent({
|
|
50
|
-
account: accounts[0],
|
|
51
|
-
scopes: [`${url}/.default`]
|
|
52
|
-
});
|
|
53
|
-
if (silentToken) {
|
|
54
|
-
return silentToken;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
catch (ex) {
|
|
58
|
-
if (ex.message.indexOf('The refresh token has expired due to inactivity') === -1) {
|
|
59
|
-
throw new Error(ex.message);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Acquire token by device code
|
|
64
|
-
try {
|
|
65
|
-
const token = await pca.acquireTokenByDeviceCode({
|
|
66
|
-
scopes: [`${url}/.default`],
|
|
67
|
-
deviceCodeCallback: (response) => logger_1.logger.info(response.message)
|
|
68
|
-
});
|
|
69
|
-
return token;
|
|
70
|
-
}
|
|
71
|
-
catch (ex) {
|
|
72
|
-
throw new Error(ex.message);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
exports.getAccessToken = getAccessToken;
|
package/lib/cachePlugin.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.cachePlugin = exports.deleteCache = exports.cacheExists = exports.getCachePath = void 0;
|
|
7
|
-
const os_1 = __importDefault(require("os"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const cryptr_1 = __importDefault(require("cryptr"));
|
|
11
|
-
const encrypt = (text) => {
|
|
12
|
-
const user = os_1.default.userInfo().username;
|
|
13
|
-
const cryptr = new cryptr_1.default(user);
|
|
14
|
-
const encrypted = cryptr.encrypt(text);
|
|
15
|
-
return encrypted;
|
|
16
|
-
};
|
|
17
|
-
const decrypt = (text) => {
|
|
18
|
-
const user = os_1.default.userInfo().username;
|
|
19
|
-
const cryptr = new cryptr_1.default(user);
|
|
20
|
-
const decrypted = cryptr.decrypt(text);
|
|
21
|
-
return decrypted;
|
|
22
|
-
};
|
|
23
|
-
const getCachePath = (url) => {
|
|
24
|
-
const org = new URL(url).hostname.split('.')[0];
|
|
25
|
-
if (!fs_1.default.existsSync(path_1.default.join(os_1.default.homedir(), './.dataverse-utils/'))) {
|
|
26
|
-
fs_1.default.mkdirSync(path_1.default.join(os_1.default.homedir(), './.dataverse-utils/'));
|
|
27
|
-
}
|
|
28
|
-
return path_1.default.join(os_1.default.homedir(), `./.dataverse-utils/${org}.json`);
|
|
29
|
-
};
|
|
30
|
-
exports.getCachePath = getCachePath;
|
|
31
|
-
const cacheExists = (url) => {
|
|
32
|
-
const cacheLocation = (0, exports.getCachePath)(url);
|
|
33
|
-
return fs_1.default.existsSync(cacheLocation);
|
|
34
|
-
};
|
|
35
|
-
exports.cacheExists = cacheExists;
|
|
36
|
-
const deleteCache = (url) => {
|
|
37
|
-
const cacheLocation = (0, exports.getCachePath)(url);
|
|
38
|
-
if (fs_1.default.existsSync(cacheLocation)) {
|
|
39
|
-
fs_1.default.unlinkSync(cacheLocation);
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
exports.deleteCache = deleteCache;
|
|
47
|
-
const cachePlugin = (url) => {
|
|
48
|
-
const cacheLocation = (0, exports.getCachePath)(url);
|
|
49
|
-
const beforeCacheAccess = (tokenCacheContext) => {
|
|
50
|
-
return new Promise((resolve, reject) => {
|
|
51
|
-
if (fs_1.default.existsSync(cacheLocation)) {
|
|
52
|
-
fs_1.default.readFile(cacheLocation, 'utf-8', (err, data) => {
|
|
53
|
-
if (err) {
|
|
54
|
-
reject();
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
try {
|
|
58
|
-
const decrypted = decrypt(data);
|
|
59
|
-
tokenCacheContext.tokenCache.deserialize(decrypted);
|
|
60
|
-
resolve();
|
|
61
|
-
}
|
|
62
|
-
catch (ex) {
|
|
63
|
-
reject(ex);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
try {
|
|
70
|
-
const encrypted = encrypt(tokenCacheContext.tokenCache.serialize());
|
|
71
|
-
fs_1.default.writeFile(cacheLocation, encrypted, (err) => {
|
|
72
|
-
if (err) {
|
|
73
|
-
reject();
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
resolve();
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
catch (ex) {
|
|
81
|
-
reject(ex);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
const afterCacheAccess = (tokenCacheContext) => {
|
|
87
|
-
return new Promise((resolve, reject) => {
|
|
88
|
-
if (tokenCacheContext.cacheHasChanged) {
|
|
89
|
-
const encrypted = encrypt(tokenCacheContext.tokenCache.serialize());
|
|
90
|
-
fs_1.default.writeFile(cacheLocation, encrypted, (err) => {
|
|
91
|
-
if (err) {
|
|
92
|
-
reject(err);
|
|
93
|
-
}
|
|
94
|
-
resolve();
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
resolve();
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
return {
|
|
103
|
-
beforeCacheAccess,
|
|
104
|
-
afterCacheAccess
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
exports.cachePlugin = cachePlugin;
|
package/lib/dataverse.service.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTableMetadata = exports.publish = exports.addToSolution = exports.ComponentType = void 0;
|
|
4
|
-
const node_1 = require("dataverse-webapi/lib/node");
|
|
5
|
-
const logger_1 = require("./logger");
|
|
6
|
-
var ComponentType;
|
|
7
|
-
(function (ComponentType) {
|
|
8
|
-
ComponentType[ComponentType["WebResource"] = 61] = "WebResource";
|
|
9
|
-
ComponentType[ComponentType["PluginType"] = 90] = "PluginType";
|
|
10
|
-
ComponentType[ComponentType["PluginAssembly"] = 91] = "PluginAssembly";
|
|
11
|
-
ComponentType[ComponentType["SDKMessageProcessingStep"] = 92] = "SDKMessageProcessingStep";
|
|
12
|
-
ComponentType[ComponentType["SDKMessageProcessingStepImage"] = 93] = "SDKMessageProcessingStepImage";
|
|
13
|
-
ComponentType[ComponentType["PluginPackage"] = 10865] = "PluginPackage";
|
|
14
|
-
})(ComponentType = exports.ComponentType || (exports.ComponentType = {}));
|
|
15
|
-
async function addToSolution(id, solution, type, apiConfig) {
|
|
16
|
-
const data = {
|
|
17
|
-
ComponentId: id,
|
|
18
|
-
ComponentType: type,
|
|
19
|
-
SolutionUniqueName: solution,
|
|
20
|
-
AddRequiredComponents: false,
|
|
21
|
-
IncludedComponentSettingsValues: null
|
|
22
|
-
};
|
|
23
|
-
logger_1.logger.info(`add component ${id} to solution ${solution}`);
|
|
24
|
-
await (0, node_1.unboundAction)(apiConfig, 'AddSolutionComponent', data);
|
|
25
|
-
}
|
|
26
|
-
exports.addToSolution = addToSolution;
|
|
27
|
-
async function publish(publishXml, apiConfig) {
|
|
28
|
-
const data = {
|
|
29
|
-
ParameterXml: `<importexportxml><webresources>${publishXml}</webresources></importexportxml>`
|
|
30
|
-
};
|
|
31
|
-
await (0, node_1.unboundAction)(apiConfig, 'PublishXml', data);
|
|
32
|
-
}
|
|
33
|
-
exports.publish = publish;
|
|
34
|
-
async function getTableMetadata(table, apiConfig) {
|
|
35
|
-
const options = [
|
|
36
|
-
'?$select=DisplayName,LogicalName,EntitySetName,SchemaName',
|
|
37
|
-
'&$expand=Attributes($select=LogicalName,SchemaName)'
|
|
38
|
-
].join('');
|
|
39
|
-
const metadata = await (0, node_1.retrieveMultiple)(apiConfig, `EntityDefinitions(LogicalName='${table}')`, options);
|
|
40
|
-
if (metadata == null) {
|
|
41
|
-
throw Error(`Table ${table} not found in metadata cache`);
|
|
42
|
-
}
|
|
43
|
-
const choiceOptions = [
|
|
44
|
-
'?$select=attributevalue,value,attributename',
|
|
45
|
-
`&$filter=objecttypecode eq '${table}'`
|
|
46
|
-
].join('');
|
|
47
|
-
const choiceMetadata = await (0, node_1.retrieveMultiple)(apiConfig, 'stringmaps', choiceOptions);
|
|
48
|
-
const tableMetadata = {
|
|
49
|
-
logicalName: metadata.LogicalName,
|
|
50
|
-
schemaName: metadata.SchemaName,
|
|
51
|
-
entitySetName: metadata.EntitySetName,
|
|
52
|
-
choices: [],
|
|
53
|
-
fields: metadata.Attributes.map((a) => {
|
|
54
|
-
return {
|
|
55
|
-
logicalName: a.LogicalName,
|
|
56
|
-
schemaName: a.SchemaName
|
|
57
|
-
};
|
|
58
|
-
})
|
|
59
|
-
};
|
|
60
|
-
choiceMetadata.value.forEach((c) => {
|
|
61
|
-
const index = tableMetadata.choices.findIndex(x => x.column === c.attributename);
|
|
62
|
-
if (index === -1) {
|
|
63
|
-
tableMetadata.choices.push({ column: c.attributename, options: [{ text: c.value, value: c.attributevalue }] });
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
tableMetadata.choices[index].options.push({ text: c.value, value: c.attributevalue });
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
return tableMetadata;
|
|
70
|
-
}
|
|
71
|
-
exports.getTableMetadata = getTableMetadata;
|
package/lib/deploy.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const prompts_1 = __importDefault(require("prompts"));
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const logger_1 = require("./logger");
|
|
10
|
-
const assemblyDeploy_1 = require("./assemblyDeploy");
|
|
11
|
-
const webResourceDeploy_1 = require("./webResourceDeploy");
|
|
12
|
-
const node_1 = require("dataverse-webapi/lib/node");
|
|
13
|
-
const auth_1 = require("./auth");
|
|
14
|
-
async function deploy(type, files) {
|
|
15
|
-
if (!type || (type !== 'webresource' && type !== 'assembly' && type !== 'pcf')) {
|
|
16
|
-
const invalid = type !== undefined && type !== 'webresource' && type !== 'assembly' && type !== 'pcf';
|
|
17
|
-
const invalidMessage = invalid ? `${type} is not a valid project type. ` : '';
|
|
18
|
-
const { typePrompt } = await (0, prompts_1.default)({
|
|
19
|
-
type: 'select',
|
|
20
|
-
name: 'typePrompt',
|
|
21
|
-
message: `${invalidMessage}select project type to deploy`,
|
|
22
|
-
choices: [
|
|
23
|
-
{ title: 'web resource', value: 'webresource' },
|
|
24
|
-
{ title: 'pcf', value: 'webresource' },
|
|
25
|
-
{ title: 'plugin or workflow activity', value: 'assembly' }
|
|
26
|
-
]
|
|
27
|
-
});
|
|
28
|
-
type = typePrompt;
|
|
29
|
-
}
|
|
30
|
-
const currentPath = '.';
|
|
31
|
-
const credsFile = await fs_1.default.promises.readFile(path_1.default.resolve(currentPath, 'dataverse.config.json'), 'utf8');
|
|
32
|
-
if (credsFile == null) {
|
|
33
|
-
logger_1.logger.warn('unable to find dataverse.config.json file');
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const creds = JSON.parse(credsFile).connection;
|
|
37
|
-
if (!creds.authEndpoint) {
|
|
38
|
-
logger_1.logger.error(('authEndpoint not found in dataverse.config.json. if you recently updated the package, please update the config file and replace tenant with authEndpoint with full authorization URL.'));
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
let token = null;
|
|
42
|
-
// Check if token is available in environment
|
|
43
|
-
if (process.env.ACCESSTOKEN) {
|
|
44
|
-
token = { accessToken: process.env.ACCESSTOKEN };
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
try {
|
|
48
|
-
token = await (0, auth_1.getAccessToken)(creds.authEndpoint, creds.server);
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
(0, auth_1.onTokenFailure)(creds.server, error.message);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (token == null || token.accessToken == null) {
|
|
55
|
-
(0, auth_1.onTokenFailure)(creds.server);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const apiConfig = new node_1.WebApiConfig('8.2', token.accessToken, creds.server);
|
|
60
|
-
switch (type) {
|
|
61
|
-
case 'webresource':
|
|
62
|
-
await (0, webResourceDeploy_1.webResourceDeploy)(creds, apiConfig, files);
|
|
63
|
-
break;
|
|
64
|
-
case 'assembly':
|
|
65
|
-
await (0, assemblyDeploy_1.assemblyDeploy)(creds, apiConfig);
|
|
66
|
-
break;
|
|
67
|
-
case 'pcf':
|
|
68
|
-
logger_1.logger.error('PCF deploy coming soon');
|
|
69
|
-
break;
|
|
70
|
-
default:
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.default = deploy;
|
package/lib/generate.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const prompts_1 = __importDefault(require("prompts"));
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const logger_1 = require("./logger");
|
|
10
|
-
const dataverse_service_1 = require("./dataverse.service");
|
|
11
|
-
const node_1 = require("dataverse-webapi/lib/node");
|
|
12
|
-
const auth_1 = require("./auth");
|
|
13
|
-
async function generate(table) {
|
|
14
|
-
while (!table) {
|
|
15
|
-
const { tablePrompt } = await (0, prompts_1.default)({
|
|
16
|
-
type: 'text',
|
|
17
|
-
name: 'tablePrompt',
|
|
18
|
-
message: `enter table to generate`
|
|
19
|
-
});
|
|
20
|
-
table = tablePrompt;
|
|
21
|
-
}
|
|
22
|
-
const currentPath = '.';
|
|
23
|
-
const credsFile = await fs_1.default.promises.readFile(path_1.default.resolve(currentPath, 'dataverse.config.json'), 'utf8');
|
|
24
|
-
if (credsFile == null) {
|
|
25
|
-
logger_1.logger.warn('unable to find dataverse.config.json file');
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const creds = JSON.parse(credsFile).connection;
|
|
29
|
-
if (!creds.authEndpoint) {
|
|
30
|
-
logger_1.logger.error(('authEndpoint not found in dataverse.config.json. if you recently updated the package, please update the config file and replace tenant with authEndpoint with full authorization URL.'));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
let token = null;
|
|
34
|
-
try {
|
|
35
|
-
token = await (0, auth_1.getAccessToken)(creds.authEndpoint, creds.server);
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
(0, auth_1.onTokenFailure)(creds.server, error.message);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (token == null || token.accessToken == null) {
|
|
42
|
-
(0, auth_1.onTokenFailure)(creds.server);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const apiConfig = new node_1.WebApiConfig('8.2', token.accessToken, creds.server);
|
|
46
|
-
let metadata = {};
|
|
47
|
-
logger_1.logger.info('Retrieve table metadata');
|
|
48
|
-
try {
|
|
49
|
-
metadata = await (0, dataverse_service_1.getTableMetadata)(table, apiConfig);
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
logger_1.logger.error(error.message);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
// Build code file from metadata
|
|
56
|
-
const codeFile = [
|
|
57
|
-
`class ${metadata.schemaName} {`,
|
|
58
|
-
'\r\n',
|
|
59
|
-
` LogicalName = '${metadata.logicalName}';`,
|
|
60
|
-
'\r\n',
|
|
61
|
-
` SchemaName = '${metadata.schemaName}';`,
|
|
62
|
-
'\r\n',
|
|
63
|
-
` EntitySetName = '${metadata.entitySetName}';`,
|
|
64
|
-
'\r\n',
|
|
65
|
-
'\r\n',
|
|
66
|
-
' Fields = {',
|
|
67
|
-
'\r\n',
|
|
68
|
-
metadata.fields.map(f => {
|
|
69
|
-
return ` '${f.schemaName}': '${f.logicalName}'`;
|
|
70
|
-
}).join(',\r\n'),
|
|
71
|
-
'\r\n',
|
|
72
|
-
' }',
|
|
73
|
-
'\r\n',
|
|
74
|
-
'\r\n',
|
|
75
|
-
metadata.choices.map(c => {
|
|
76
|
-
const field = metadata.fields.find(f => f.logicalName === c.column);
|
|
77
|
-
return ` ${field?.schemaName ?? c.column} = ${metadata.schemaName}_${field?.schemaName ?? c.column};`;
|
|
78
|
-
}).join('\r\n'),
|
|
79
|
-
'\r\n',
|
|
80
|
-
'}',
|
|
81
|
-
'\r\n',
|
|
82
|
-
'\r\n',
|
|
83
|
-
metadata.choices.map(c => {
|
|
84
|
-
const field = metadata.fields.find(f => f.logicalName === c.column);
|
|
85
|
-
return [
|
|
86
|
-
`export enum ${metadata.schemaName}_${field?.schemaName ?? c.column} {`,
|
|
87
|
-
'\r\n',
|
|
88
|
-
c.options.map(x => ` '${x.text.replace(`'`, `\\'`)}' = ${x.value}`).join(',\r\n'),
|
|
89
|
-
'\r\n',
|
|
90
|
-
'}'
|
|
91
|
-
].join('');
|
|
92
|
-
}).join('\r\n\r\n'),
|
|
93
|
-
'\r\n',
|
|
94
|
-
'\r\n',
|
|
95
|
-
`export default new ${metadata.schemaName}();`
|
|
96
|
-
].join('');
|
|
97
|
-
if (!fs_1.default.existsSync(path_1.default.resolve(currentPath, 'src', 'scripts', 'models'))) {
|
|
98
|
-
fs_1.default.mkdirSync(path_1.default.resolve(currentPath, 'src', 'scripts', 'models'));
|
|
99
|
-
}
|
|
100
|
-
fs_1.default.writeFileSync(path_1.default.resolve(currentPath, 'src', 'scripts', 'models', `${metadata.schemaName}.ts`), codeFile);
|
|
101
|
-
logger_1.logger.done(`Table metadata output to models/${metadata.schemaName}.ts`);
|
|
102
|
-
}
|
|
103
|
-
exports.default = generate;
|
package/lib/index.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const commander_1 = require("commander");
|
|
8
|
-
const deploy_1 = __importDefault(require("./deploy"));
|
|
9
|
-
const generate_1 = __importDefault(require("./generate"));
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
11
|
-
const packageJson = require('../package.json');
|
|
12
|
-
commander_1.program
|
|
13
|
-
.version(packageJson.version)
|
|
14
|
-
.usage('<command> [options]');
|
|
15
|
-
// Deploy command
|
|
16
|
-
commander_1.program
|
|
17
|
-
.command('deploy')
|
|
18
|
-
.description('Deploy file(s) to dataverse (webresource, assembly, pcf)')
|
|
19
|
-
.argument('[type]', 'Type of project to deploy')
|
|
20
|
-
.argument('[files]', 'Comma separate list of files to deploy')
|
|
21
|
-
.action((type, files) => {
|
|
22
|
-
(0, deploy_1.default)(type, files);
|
|
23
|
-
});
|
|
24
|
-
// Generate command
|
|
25
|
-
commander_1.program
|
|
26
|
-
.command('generate')
|
|
27
|
-
.description('Generate early-bound TypeScript file for specified table')
|
|
28
|
-
.argument('[table]', 'Table to generate')
|
|
29
|
-
.action((table) => {
|
|
30
|
-
(0, generate_1.default)(table);
|
|
31
|
-
});
|
|
32
|
-
// Show help on unknown command
|
|
33
|
-
commander_1.program
|
|
34
|
-
.arguments('<command>')
|
|
35
|
-
.action((cmd) => {
|
|
36
|
-
commander_1.program.outputHelp();
|
|
37
|
-
console.log();
|
|
38
|
-
console.log(`Unknown command ${cmd}.`);
|
|
39
|
-
console.log();
|
|
40
|
-
});
|
|
41
|
-
commander_1.program.parse(process.argv);
|
|
42
|
-
if (!process.argv.slice(2).length) {
|
|
43
|
-
commander_1.program.outputHelp();
|
|
44
|
-
}
|
package/lib/logger.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.logger = exports.icons = void 0;
|
|
7
|
-
const kleur_1 = __importDefault(require("kleur"));
|
|
8
|
-
const figures_1 = __importDefault(require("figures"));
|
|
9
|
-
const isTest = process.env.JEST_WORKER_ID !== undefined;
|
|
10
|
-
exports.icons = {
|
|
11
|
-
done: kleur_1.default.green(figures_1.default.tick),
|
|
12
|
-
info: kleur_1.default.cyan(figures_1.default.pointer),
|
|
13
|
-
error: kleur_1.default.red(figures_1.default.cross),
|
|
14
|
-
warn: kleur_1.default.yellow(figures_1.default.warning)
|
|
15
|
-
};
|
|
16
|
-
exports.logger = {
|
|
17
|
-
info(...args) {
|
|
18
|
-
if (!isTest) {
|
|
19
|
-
console.info(exports.icons.info, ...args);
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
warn(...args) {
|
|
23
|
-
if (!isTest) {
|
|
24
|
-
console.warn(exports.icons.warn, ...args);
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
error(...args) {
|
|
28
|
-
if (!isTest) {
|
|
29
|
-
console.error(exports.icons.error, ...args);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
done(...args) {
|
|
33
|
-
if (!isTest) {
|
|
34
|
-
console.info(exports.icons.done, ...args);
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
};
|
package/lib/models/customApi.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.retrieveApi = exports.deployApi = void 0;
|
|
4
|
-
const node_1 = require("dataverse-webapi/lib/node");
|
|
5
|
-
const pluginType_1 = require("./pluginType");
|
|
6
|
-
const logger_1 = require("../logger");
|
|
7
|
-
async function deployApi(config, assemblyId, apiConfig, solution) {
|
|
8
|
-
const api = structuredClone(config);
|
|
9
|
-
if (!config.customapiid) {
|
|
10
|
-
config.customapiid = await retrieveApi(api.name, apiConfig);
|
|
11
|
-
}
|
|
12
|
-
if (config.plugintype && !config.plugintypeid) {
|
|
13
|
-
config.plugintypeid = await (0, pluginType_1.retrieveType)(config.plugintype, assemblyId, apiConfig);
|
|
14
|
-
if (config.plugintypeid === '') {
|
|
15
|
-
logger_1.logger.error(`unable to find plugin type ${api.plugintype}`);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
delete api.plugintype;
|
|
20
|
-
delete api.customapiid;
|
|
21
|
-
delete api.plugintypeid;
|
|
22
|
-
api['PluginTypeId@odata.bind'] = `plugintypes(${config.plugintypeid})`;
|
|
23
|
-
if (config.customapiid !== '') {
|
|
24
|
-
try {
|
|
25
|
-
await updateApi(config.customapiid, api, apiConfig);
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
throw new Error(`failed to update custom api: ${error.message}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
try {
|
|
33
|
-
config.customapiid = await createApi(api, apiConfig, solution);
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
throw new Error(`failed to create custom api: ${error.message}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.deployApi = deployApi;
|
|
41
|
-
async function retrieveApi(name, apiConfig) {
|
|
42
|
-
const options = `$select=customapiid&$filter=name eq '${name}'`;
|
|
43
|
-
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'customapis', options);
|
|
44
|
-
return result.value.length > 0 ? result.value[0].customapiid : '';
|
|
45
|
-
}
|
|
46
|
-
exports.retrieveApi = retrieveApi;
|
|
47
|
-
async function createApi(api, apiConfig, solution) {
|
|
48
|
-
logger_1.logger.info(`create custom api ${api.name}`);
|
|
49
|
-
const options = {};
|
|
50
|
-
if (solution) {
|
|
51
|
-
options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
|
|
52
|
-
}
|
|
53
|
-
const result = await (0, node_1.createWithReturnData)(apiConfig, 'customapis', api, '$select=customapiid', options);
|
|
54
|
-
if (result?.error) {
|
|
55
|
-
throw new Error(result.error.message);
|
|
56
|
-
}
|
|
57
|
-
return result.customapiid;
|
|
58
|
-
}
|
|
59
|
-
async function updateApi(id, api, apiConfig) {
|
|
60
|
-
logger_1.logger.info(`update custom api ${api.name}`);
|
|
61
|
-
const record = {
|
|
62
|
-
displayname: api.displayname,
|
|
63
|
-
description: api.description,
|
|
64
|
-
name: api.name,
|
|
65
|
-
executeprivilegename: api.executeprivilegename
|
|
66
|
-
};
|
|
67
|
-
if (api['PluginTypeId@odata.bind']) {
|
|
68
|
-
record['PluginTypeId@odata.bind'] = api['PluginTypeId@odata.bind'];
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
record['PluginTypeId@odata.bind'] = null;
|
|
72
|
-
}
|
|
73
|
-
const result = await (0, node_1.update)(apiConfig, 'customapis', id, record);
|
|
74
|
-
if (result?.error) {
|
|
75
|
-
throw new Error(result.error.message);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.retrieveAssembly = exports.deployAssembly = void 0;
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const glob_1 = require("glob");
|
|
10
|
-
const node_1 = require("dataverse-webapi/lib/node");
|
|
11
|
-
const pluginType_1 = require("./pluginType");
|
|
12
|
-
const logger_1 = require("../logger");
|
|
13
|
-
async function deployAssembly(config, apiConfig, solution) {
|
|
14
|
-
const files = await (0, glob_1.glob)(`bin/Debug/**/${config.name}.dll`);
|
|
15
|
-
if (files.length === 0) {
|
|
16
|
-
logger_1.logger.warn(`assembly ${config.name}.dll not found`);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const content = (await fs_1.default.promises.readFile(files[0])).toString('base64');
|
|
20
|
-
if (!config.pluginassemblyid) {
|
|
21
|
-
config.pluginassemblyid = await retrieveAssembly(config.name, apiConfig);
|
|
22
|
-
}
|
|
23
|
-
if (config.pluginassemblyid !== '') {
|
|
24
|
-
try {
|
|
25
|
-
await updateAssembly(config, content, apiConfig);
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
throw new Error(`failed to update assembly: ${error.message}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
try {
|
|
33
|
-
config.pluginassemblyid = await createAssembly(config, content, apiConfig, solution);
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
throw new Error(`failed to create assembly: ${error.message}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (config.types != null) {
|
|
40
|
-
try {
|
|
41
|
-
const promises = config.types.map((type) => (0, pluginType_1.deployType)(type, config.pluginassemblyid, apiConfig, solution));
|
|
42
|
-
await Promise.all(promises);
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
logger_1.logger.error(error.message);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.deployAssembly = deployAssembly;
|
|
51
|
-
async function retrieveAssembly(name, apiConfig) {
|
|
52
|
-
const options = `$select=pluginassemblyid&$filter=name eq '${name}'`;
|
|
53
|
-
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'pluginassemblies', options);
|
|
54
|
-
return result.value.length > 0 ? result.value[0].pluginassemblyid : '';
|
|
55
|
-
}
|
|
56
|
-
exports.retrieveAssembly = retrieveAssembly;
|
|
57
|
-
async function createAssembly(config, content, apiConfig, solution) {
|
|
58
|
-
logger_1.logger.info(`create assembly ${config.name}`);
|
|
59
|
-
const assembly = {
|
|
60
|
-
name: config.name,
|
|
61
|
-
content: content,
|
|
62
|
-
isolationmode: config.isolationmode,
|
|
63
|
-
version: config.version,
|
|
64
|
-
publickeytoken: config.name,
|
|
65
|
-
sourcetype: 0,
|
|
66
|
-
culture: ''
|
|
67
|
-
};
|
|
68
|
-
const options = {};
|
|
69
|
-
if (solution) {
|
|
70
|
-
options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
|
|
71
|
-
}
|
|
72
|
-
const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginassemblies', assembly, '$select=pluginassemblyid', options);
|
|
73
|
-
if (result?.error) {
|
|
74
|
-
throw new Error(result.error.message);
|
|
75
|
-
}
|
|
76
|
-
return result.pluginassemblyid;
|
|
77
|
-
}
|
|
78
|
-
async function updateAssembly(config, content, apiConfig) {
|
|
79
|
-
logger_1.logger.info(`update assembly ${config.name}`);
|
|
80
|
-
const assembly = {
|
|
81
|
-
content: content,
|
|
82
|
-
version: config.version
|
|
83
|
-
};
|
|
84
|
-
const result = await (0, node_1.update)(apiConfig, 'pluginassemblies', config.pluginassemblyid, assembly);
|
|
85
|
-
if (result?.error) {
|
|
86
|
-
throw new Error(result.error.message);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deployImage = void 0;
|
|
4
|
-
const logger_1 = require("../logger");
|
|
5
|
-
const node_1 = require("dataverse-webapi/lib/node");
|
|
6
|
-
async function deployImage(stepId, stepName, config, message, apiConfig) {
|
|
7
|
-
const image = structuredClone(config);
|
|
8
|
-
image['sdkmessageprocessingstepid@odata.bind'] = `/sdkmessageprocessingsteps(${stepId})`;
|
|
9
|
-
switch (message) {
|
|
10
|
-
case 'Create':
|
|
11
|
-
image.messagepropertyname = 'Id';
|
|
12
|
-
break;
|
|
13
|
-
case 'SetState':
|
|
14
|
-
case 'SetStateDynamicEntity':
|
|
15
|
-
image.messagepropertyname = 'EntityMoniker';
|
|
16
|
-
break;
|
|
17
|
-
case 'Send':
|
|
18
|
-
case 'DeliverIncoming':
|
|
19
|
-
case 'DeliverPromote':
|
|
20
|
-
image.messagepropertyname = 'EmailId';
|
|
21
|
-
break;
|
|
22
|
-
default:
|
|
23
|
-
image.messagepropertyname = 'Target';
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
if (!config.sdkmessageprocessingstepimageid) {
|
|
27
|
-
config.sdkmessageprocessingstepimageid = await retrieveImage(stepId, image, apiConfig);
|
|
28
|
-
}
|
|
29
|
-
if (config.sdkmessageprocessingstepimageid !== '') {
|
|
30
|
-
try {
|
|
31
|
-
await updateImage(config.sdkmessageprocessingstepimageid, image, stepName, apiConfig);
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
throw new Error(`failed to update plugin image: ${error.message}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
try {
|
|
39
|
-
config.sdkmessageprocessingstepimageid = await createImage(image, stepName, apiConfig);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
throw new Error(`failed to create plugin image: ${error.message}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.deployImage = deployImage;
|
|
47
|
-
async function retrieveImage(stepId, image, apiConfig) {
|
|
48
|
-
const options = `$select=sdkmessageprocessingstepimageid&$filter=name eq '${image.name}' and _sdkmessageprocessingstepid_value eq ${stepId}`;
|
|
49
|
-
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessageprocessingstepimages', options);
|
|
50
|
-
return result.value.length > 0 ? result.value[0].sdkmessageprocessingstepimageid : '';
|
|
51
|
-
}
|
|
52
|
-
async function createImage(image, stepName, apiConfig) {
|
|
53
|
-
logger_1.logger.info(`create plugin image ${image.name} for step ${stepName}`);
|
|
54
|
-
const result = await (0, node_1.createWithReturnData)(apiConfig, 'sdkmessageprocessingstepimages', image, '$select=sdkmessageprocessingstepimageid');
|
|
55
|
-
if (result?.error) {
|
|
56
|
-
throw new Error(result.error.message);
|
|
57
|
-
}
|
|
58
|
-
return result.sdkmessageprocessingstepimageid;
|
|
59
|
-
}
|
|
60
|
-
async function updateImage(id, image, stepName, apiConfig) {
|
|
61
|
-
logger_1.logger.info(`update plugin image ${image.name} for step ${stepName}`);
|
|
62
|
-
const entity = { ...image };
|
|
63
|
-
delete entity.sdkmessageprocessingstepimageid;
|
|
64
|
-
const result = await (0, node_1.update)(apiConfig, 'sdkmessageprocessingstepimages', id, entity);
|
|
65
|
-
if (result?.error) {
|
|
66
|
-
throw new Error(result.error.message);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.deployPluginPackage = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const glob_1 = require("glob");
|
|
9
|
-
const node_1 = require("dataverse-webapi/lib/node");
|
|
10
|
-
const pluginAssembly_1 = require("./pluginAssembly");
|
|
11
|
-
const logger_1 = require("../logger");
|
|
12
|
-
const pluginType_1 = require("./pluginType");
|
|
13
|
-
const pluginStep_1 = require("./pluginStep");
|
|
14
|
-
async function deployPluginPackage(config, apiConfig, solution) {
|
|
15
|
-
const files = await (0, glob_1.glob)(`**/${config.name}.*.nupkg`);
|
|
16
|
-
if (files.length === 0) {
|
|
17
|
-
logger_1.logger.warn(`package ${config.name}.nupkg not found`);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const content = (await fs_1.default.promises.readFile(files[0])).toString('base64');
|
|
21
|
-
if (!config.pluginpackageid) {
|
|
22
|
-
config.pluginpackageid = await retrievePackage(config.prefix, config.name, apiConfig);
|
|
23
|
-
}
|
|
24
|
-
if (config.pluginpackageid) {
|
|
25
|
-
try {
|
|
26
|
-
await updatePackage(config, content, apiConfig);
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
throw new Error(`failed to update package: ${error.message}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
try {
|
|
34
|
-
config.pluginpackageid = await createPackage(config, content, apiConfig, solution);
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
throw new Error(`failed to create package: ${error.message}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (config.assembly != null) {
|
|
41
|
-
try {
|
|
42
|
-
if (!config.assembly.pluginassemblyid) {
|
|
43
|
-
config.assembly.pluginassemblyid = await (0, pluginAssembly_1.retrieveAssembly)(config.assembly.name, apiConfig);
|
|
44
|
-
}
|
|
45
|
-
const promises = config.assembly.types?.map(async (t) => {
|
|
46
|
-
if (!t.plugintypeid && config.assembly?.pluginassemblyid) {
|
|
47
|
-
t.plugintypeid = await (0, pluginType_1.retrieveType)(t.typename, config.assembly.pluginassemblyid, apiConfig);
|
|
48
|
-
}
|
|
49
|
-
const stepPromises = t.steps?.map((s) => (0, pluginStep_1.deployStep)(s, t.plugintypeid, apiConfig, solution)) ?? [];
|
|
50
|
-
await Promise.all(stepPromises);
|
|
51
|
-
}) ?? [];
|
|
52
|
-
await Promise.all(promises);
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
logger_1.logger.error(error.message);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.deployPluginPackage = deployPluginPackage;
|
|
61
|
-
async function retrievePackage(prefix, name, apiConfig) {
|
|
62
|
-
const options = `$select=pluginpackageid&$filter=contains(name, '${prefix}_${name}')`;
|
|
63
|
-
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'pluginpackages', options);
|
|
64
|
-
return result.value.length > 0 ? result.value[0].pluginpackageid : '';
|
|
65
|
-
}
|
|
66
|
-
async function createPackage(config, content, apiConfig, solution) {
|
|
67
|
-
logger_1.logger.info(`create package ${config.name}`);
|
|
68
|
-
const pluginPackage = {
|
|
69
|
-
name: `${config.prefix}_${config.name}`,
|
|
70
|
-
version: config.version,
|
|
71
|
-
content: content
|
|
72
|
-
};
|
|
73
|
-
const options = {};
|
|
74
|
-
if (solution) {
|
|
75
|
-
options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
|
|
76
|
-
}
|
|
77
|
-
const result = await (0, node_1.createWithReturnData)(apiConfig, 'pluginpackages', pluginPackage, '$select=pluginpackageid', options);
|
|
78
|
-
if (result?.error) {
|
|
79
|
-
throw new Error(result.error.message);
|
|
80
|
-
}
|
|
81
|
-
return result.pluginpackageid;
|
|
82
|
-
}
|
|
83
|
-
async function updatePackage(config, content, apiConfig) {
|
|
84
|
-
logger_1.logger.info(`update package ${config.name}`);
|
|
85
|
-
const updated = {
|
|
86
|
-
content: content,
|
|
87
|
-
version: config.version
|
|
88
|
-
};
|
|
89
|
-
const result = await (0, node_1.update)(apiConfig, 'pluginpackages', config.pluginpackageid, updated);
|
|
90
|
-
if (result?.error) {
|
|
91
|
-
throw new Error(result.error.message);
|
|
92
|
-
}
|
|
93
|
-
}
|
package/lib/models/pluginStep.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deployStep = void 0;
|
|
4
|
-
const node_1 = require("dataverse-webapi/lib/node");
|
|
5
|
-
const logger_1 = require("../logger");
|
|
6
|
-
const pluginImage_1 = require("./pluginImage");
|
|
7
|
-
async function deployStep(config, pluginTypeId, apiConfig, solution) {
|
|
8
|
-
const step = structuredClone(config);
|
|
9
|
-
step['plugintypeid@odata.bind'] = `/plugintypes(${pluginTypeId})`;
|
|
10
|
-
const messageId = await getSdkMessageId(step.message ?? '', apiConfig);
|
|
11
|
-
if (messageId == '') {
|
|
12
|
-
logger_1.logger.warn(`sdk message ${step.message} not found`);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (step.entity !== '' && step.entity !== 'none') {
|
|
16
|
-
const filterId = await getSdkMessageFilterId(messageId, step.entity ?? '', apiConfig);
|
|
17
|
-
if (filterId == '') {
|
|
18
|
-
logger_1.logger.warn(`sdk message ${step.message} for entity ${step.entity} not found`);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
step['sdkmessagefilterid@odata.bind'] = `/sdkmessagefilters(${filterId})`;
|
|
22
|
-
}
|
|
23
|
-
step['sdkmessageid@odata.bind'] = `/sdkmessages(${messageId})`;
|
|
24
|
-
step.asyncautodelete = step.mode === 1;
|
|
25
|
-
delete step.images;
|
|
26
|
-
delete step.message;
|
|
27
|
-
delete step.entity;
|
|
28
|
-
delete step.sdkmessageprocessingstepid;
|
|
29
|
-
if (!config.sdkmessageprocessingstepid) {
|
|
30
|
-
config.sdkmessageprocessingstepid = await retrieveStep(step.name, pluginTypeId, apiConfig);
|
|
31
|
-
}
|
|
32
|
-
if (config.sdkmessageprocessingstepid !== '') {
|
|
33
|
-
try {
|
|
34
|
-
await updateStep(config.sdkmessageprocessingstepid, step, apiConfig);
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
throw new Error(`failed to update plugin step: ${error.message}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
try {
|
|
42
|
-
config.sdkmessageprocessingstepid = await createStep(step, apiConfig, solution);
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
throw new Error(`failed to create plugin step: ${error.message}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (config.images && config.images.length > 0) {
|
|
49
|
-
try {
|
|
50
|
-
const promises = config.images.map((image) => (0, pluginImage_1.deployImage)(config.sdkmessageprocessingstepid, step.name, image, config.message, apiConfig));
|
|
51
|
-
await Promise.all(promises);
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
throw new Error(error.message);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.deployStep = deployStep;
|
|
59
|
-
async function getSdkMessageFilterId(messageId, entityName, apiConfig) {
|
|
60
|
-
const options = [
|
|
61
|
-
`?$filter=primaryobjecttypecode eq '${entityName}' and _sdkmessageid_value eq ${messageId}`,
|
|
62
|
-
'&$select=sdkmessagefilterid'
|
|
63
|
-
].join('');
|
|
64
|
-
const message = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessagefilters', options);
|
|
65
|
-
return message.value.length > 0 ? message.value[0].sdkmessagefilterid : '';
|
|
66
|
-
}
|
|
67
|
-
async function getSdkMessageId(name, apiConfig) {
|
|
68
|
-
const options = [`?$filter=name eq '${name}'`, '&$select=sdkmessageid'].join('');
|
|
69
|
-
const message = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessages', options);
|
|
70
|
-
return message.value.length > 0 ? message.value[0].sdkmessageid : '';
|
|
71
|
-
}
|
|
72
|
-
async function retrieveStep(name, typeId, apiConfig) {
|
|
73
|
-
const options = `$select=sdkmessageprocessingstepid&$filter=name eq '${name}' and _plugintypeid_value eq ${typeId}`;
|
|
74
|
-
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'sdkmessageprocessingsteps', options);
|
|
75
|
-
return result.value.length > 0 ? result.value[0].sdkmessageprocessingstepid : '';
|
|
76
|
-
}
|
|
77
|
-
async function createStep(step, apiConfig, solution) {
|
|
78
|
-
logger_1.logger.info(`create plugin step ${step.name}`);
|
|
79
|
-
const options = {};
|
|
80
|
-
if (solution) {
|
|
81
|
-
options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
|
|
82
|
-
}
|
|
83
|
-
const result = await (0, node_1.createWithReturnData)(apiConfig, 'sdkmessageprocessingsteps', step, '$select=sdkmessageprocessingstepid', options);
|
|
84
|
-
if (result?.error) {
|
|
85
|
-
throw new Error(result.error.message);
|
|
86
|
-
}
|
|
87
|
-
return result.sdkmessageprocessingstepid;
|
|
88
|
-
}
|
|
89
|
-
async function updateStep(id, step, apiConfig) {
|
|
90
|
-
logger_1.logger.info(`update plugin step ${step.name}`);
|
|
91
|
-
const entity = { ...step };
|
|
92
|
-
delete entity.sdkmessageprocessingstepid;
|
|
93
|
-
const result = await (0, node_1.update)(apiConfig, 'sdkmessageprocessingsteps', id, entity);
|
|
94
|
-
if (result?.error) {
|
|
95
|
-
throw new Error(result.error.message);
|
|
96
|
-
}
|
|
97
|
-
}
|
package/lib/models/pluginType.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.retrieveType = exports.deployType = void 0;
|
|
4
|
-
const node_1 = require("dataverse-webapi/lib/node");
|
|
5
|
-
const pluginStep_1 = require("./pluginStep");
|
|
6
|
-
const logger_1 = require("../logger");
|
|
7
|
-
async function deployType(config, assemblyId, apiConfig, solution) {
|
|
8
|
-
const type = {
|
|
9
|
-
name: config.name,
|
|
10
|
-
friendlyname: config.friendlyname,
|
|
11
|
-
typename: config.typename,
|
|
12
|
-
'pluginassemblyid@odata.bind': `pluginassemblies(${assemblyId})`,
|
|
13
|
-
workflowactivitygroupname: config.workflowactivitygroupname
|
|
14
|
-
};
|
|
15
|
-
if (!config.plugintypeid) {
|
|
16
|
-
config.plugintypeid = await retrieveType(config.name, assemblyId, apiConfig);
|
|
17
|
-
}
|
|
18
|
-
if (config.plugintypeid !== '') {
|
|
19
|
-
try {
|
|
20
|
-
await updateType(config.plugintypeid, type, apiConfig);
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
throw new Error(`failed to update plugin type: ${error.message}`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
try {
|
|
28
|
-
config.plugintypeid = await createType(type, apiConfig);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
throw new Error(`failed to create plugin type: ${error.message}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
try {
|
|
35
|
-
if (config.steps) {
|
|
36
|
-
const promises = config.steps.map((step) => (0, pluginStep_1.deployStep)(step, config.plugintypeid, apiConfig, solution));
|
|
37
|
-
await Promise.all(promises);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
throw new Error(error.message);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.deployType = deployType;
|
|
45
|
-
async function retrieveType(name, assemblyId, apiConfig) {
|
|
46
|
-
const options = `$select=plugintypeid&$filter=typename eq '${name}' and _pluginassemblyid_value eq ${assemblyId}`;
|
|
47
|
-
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'plugintypes', options);
|
|
48
|
-
return result.value.length > 0 ? result.value[0].plugintypeid : '';
|
|
49
|
-
}
|
|
50
|
-
exports.retrieveType = retrieveType;
|
|
51
|
-
async function createType(type, apiConfig) {
|
|
52
|
-
logger_1.logger.info(`create assembly type ${type.name}`);
|
|
53
|
-
const result = await (0, node_1.createWithReturnData)(apiConfig, 'plugintypes', type, '$select=plugintypeid');
|
|
54
|
-
if (result?.error) {
|
|
55
|
-
throw new Error(result.error.message);
|
|
56
|
-
}
|
|
57
|
-
return result.plugintypeid;
|
|
58
|
-
}
|
|
59
|
-
async function updateType(id, type, apiConfig) {
|
|
60
|
-
logger_1.logger.info(`update assembly type ${type.name}`);
|
|
61
|
-
const entity = { ...type };
|
|
62
|
-
delete entity.plugintypeid;
|
|
63
|
-
const result = await (0, node_1.update)(apiConfig, 'plugintypes', id, entity);
|
|
64
|
-
if (result?.error) {
|
|
65
|
-
throw new Error(result.error.message);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.deploy = void 0;
|
|
7
|
-
const dataverse_service_1 = require("../dataverse.service");
|
|
8
|
-
const node_1 = require("dataverse-webapi/lib/node");
|
|
9
|
-
const logger_1 = require("../logger");
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
function getWebResourceType(type) {
|
|
12
|
-
switch (type) {
|
|
13
|
-
case 'HTML':
|
|
14
|
-
return 1;
|
|
15
|
-
case 'CSS':
|
|
16
|
-
return 2;
|
|
17
|
-
case 'JavaScript':
|
|
18
|
-
return 3;
|
|
19
|
-
case 'XML':
|
|
20
|
-
return 4;
|
|
21
|
-
case 'PNG':
|
|
22
|
-
return 5;
|
|
23
|
-
case 'JPG':
|
|
24
|
-
return 6;
|
|
25
|
-
case 'GIF':
|
|
26
|
-
return 7;
|
|
27
|
-
case 'XAP':
|
|
28
|
-
return 8;
|
|
29
|
-
case 'XSL':
|
|
30
|
-
return 9;
|
|
31
|
-
case 'ICO':
|
|
32
|
-
return 10;
|
|
33
|
-
case 'SVG':
|
|
34
|
-
return 11;
|
|
35
|
-
case 'RESX':
|
|
36
|
-
return 12;
|
|
37
|
-
default:
|
|
38
|
-
return 0;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async function deploy(webResources, apiConfig, solution, files) {
|
|
42
|
-
const publishXml = [];
|
|
43
|
-
let resources = webResources;
|
|
44
|
-
// Use list of files if provided
|
|
45
|
-
if (files) {
|
|
46
|
-
resources = [];
|
|
47
|
-
for (const file of files.split(',')) {
|
|
48
|
-
const resource = webResources.filter((r) => r.path?.endsWith(file));
|
|
49
|
-
if (resource.length === 0) {
|
|
50
|
-
logger_1.logger.warn(`web resource ${file} not found in dataverse.config.json`);
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
resources.push(resource[0]);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const promises = resources.map(async (resource) => {
|
|
57
|
-
try {
|
|
58
|
-
if (!resource.webresourceid) {
|
|
59
|
-
resource.webresourceid = await retrieveResource(resource.name, apiConfig);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
logger_1.logger.error(`failed to retrieve resource ${resource.name}: ${error.message}`);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const fileContent = await fs_1.default.promises.readFile(resource.path, 'utf8');
|
|
67
|
-
const content = Buffer.from(fileContent).toString('base64');
|
|
68
|
-
if (resource.webresourceid !== '') {
|
|
69
|
-
try {
|
|
70
|
-
const updated = await updateResource(resource, content, apiConfig);
|
|
71
|
-
publishXml.push(updated);
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
logger_1.logger.error(`failed to update resource: ${error.message}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
try {
|
|
79
|
-
resource.webresourceid = await createResource(resource, content, apiConfig, solution);
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
logger_1.logger.error(`failed to create resource: ${error.message}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
await Promise.all(promises);
|
|
87
|
-
// publish resources
|
|
88
|
-
if (publishXml.length > 0) {
|
|
89
|
-
try {
|
|
90
|
-
await (0, dataverse_service_1.publish)(publishXml.join(''), apiConfig);
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
logger_1.logger.error(error.message);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
exports.deploy = deploy;
|
|
98
|
-
async function retrieveResource(name, apiConfig) {
|
|
99
|
-
const options = `$select=webresourceid&$filter=name eq '${name}'`;
|
|
100
|
-
const result = await (0, node_1.retrieveMultiple)(apiConfig, 'webresourceset', options);
|
|
101
|
-
return result.value.length > 0 ? result.value[0].webresourceid : '';
|
|
102
|
-
}
|
|
103
|
-
async function createResource(resource, content, apiConfig, solution) {
|
|
104
|
-
logger_1.logger.info(`create web resource ${resource.name}`);
|
|
105
|
-
const webResource = {
|
|
106
|
-
webresourcetype: getWebResourceType(resource.type),
|
|
107
|
-
name: resource.name,
|
|
108
|
-
displayname: resource.displayname || resource.name,
|
|
109
|
-
content: content
|
|
110
|
-
};
|
|
111
|
-
const options = {};
|
|
112
|
-
if (solution) {
|
|
113
|
-
options.customHeaders = { 'MSCRM.SolutionUniqueName': solution };
|
|
114
|
-
}
|
|
115
|
-
const result = await (0, node_1.createWithReturnData)(apiConfig, 'webresourceset', webResource, '$select=webresourceid', options);
|
|
116
|
-
if (result?.error) {
|
|
117
|
-
throw new Error(result.error.message);
|
|
118
|
-
}
|
|
119
|
-
return result.webresourceid;
|
|
120
|
-
}
|
|
121
|
-
async function updateResource(resource, content, apiConfig) {
|
|
122
|
-
logger_1.logger.info(`update web resource ${resource.name}`);
|
|
123
|
-
const webResource = {
|
|
124
|
-
content: content,
|
|
125
|
-
name: resource.name,
|
|
126
|
-
displayname: resource.displayname || resource.name
|
|
127
|
-
};
|
|
128
|
-
const result = await (0, node_1.update)(apiConfig, 'webresourceset', resource.webresourceid, webResource);
|
|
129
|
-
if (result?.error) {
|
|
130
|
-
throw new Error(result.error.message);
|
|
131
|
-
}
|
|
132
|
-
return `<webresource>{${resource.webresourceid}}</webresource>`;
|
|
133
|
-
}
|
package/lib/webResourceDeploy.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.webResourceDeploy = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const logger_1 = require("./logger");
|
|
10
|
-
const webResource_1 = require("./models/webResource");
|
|
11
|
-
async function webResourceDeploy(creds, apiConfig, files) {
|
|
12
|
-
const currentPath = '.';
|
|
13
|
-
const configFile = await fs_1.default.promises.readFile(path_1.default.resolve(currentPath, 'dataverse.config.json'), 'utf8');
|
|
14
|
-
if (configFile == null) {
|
|
15
|
-
logger_1.logger.warn('unable to find dataverse.config.json file');
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const config = JSON.parse(configFile);
|
|
19
|
-
const resources = config.webResources;
|
|
20
|
-
logger_1.logger.info('deploy web resources');
|
|
21
|
-
try {
|
|
22
|
-
await (0, webResource_1.deploy)(resources, apiConfig, creds.solution, files);
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
logger_1.logger.error(error.message);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
logger_1.logger.done('deployed web resources');
|
|
29
|
-
await fs_1.default.promises.writeFile(path_1.default.resolve(currentPath, 'dataverse.config.json'), JSON.stringify(config, null, 4), 'utf8');
|
|
30
|
-
}
|
|
31
|
-
exports.webResourceDeploy = webResourceDeploy;
|
package/license
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Derek Finlinson
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|