@things-factory/integration-msgraph 6.0.42
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/CHANGELOG.md +8 -0
- package/README.md +0 -0
- package/dist-server/engine/connector/graph-connector.js +75 -0
- package/dist-server/engine/connector/graph-connector.js.map +1 -0
- package/dist-server/engine/connector/index.js +4 -0
- package/dist-server/engine/connector/index.js.map +1 -0
- package/dist-server/engine/connector/modbus-tcp-server.js +41 -0
- package/dist-server/engine/connector/modbus-tcp-server.js.map +1 -0
- package/dist-server/engine/connector/modbus-tcp.js +145 -0
- package/dist-server/engine/connector/modbus-tcp.js.map +1 -0
- package/dist-server/engine/connector/msgraph-connector.js +75 -0
- package/dist-server/engine/connector/msgraph-connector.js.map +1 -0
- package/dist-server/engine/index.js +5 -0
- package/dist-server/engine/index.js.map +1 -0
- package/dist-server/engine/task/get-users.js +47 -0
- package/dist-server/engine/task/get-users.js.map +1 -0
- package/dist-server/engine/task/index.js +4 -0
- package/dist-server/engine/task/index.js.map +1 -0
- package/dist-server/engine/task/modbus-read.js +55 -0
- package/dist-server/engine/task/modbus-read.js.map +1 -0
- package/dist-server/engine/task/modbus-write-single.js +51 -0
- package/dist-server/engine/task/modbus-write-single.js.map +1 -0
- package/dist-server/engine/task/msgraph-get-users.js +41 -0
- package/dist-server/engine/task/msgraph-get-users.js.map +1 -0
- package/dist-server/index.js +4 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/package.json +31 -0
- package/server/engine/connector/index.ts +1 -0
- package/server/engine/connector/msgraph-connector.ts +91 -0
- package/server/engine/index.ts +2 -0
- package/server/engine/task/index.ts +1 -0
- package/server/engine/task/msgraph-get-users.ts +45 -0
- package/server/index.ts +1 -0
- package/things-factory.config.js +1 -0
- package/translations/en.json +1 -0
- package/translations/ko.json +1 -0
- package/translations/ms.json +1 -0
- package/translations/zh.json +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
6
|
+
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
<!-- ## [Unreleased] -->
|
package/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MsGraphConnector = void 0;
|
|
4
|
+
/* fetch polyfil */
|
|
5
|
+
require("cross-fetch/polyfill");
|
|
6
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
7
|
+
const azure = require('@azure/identity');
|
|
8
|
+
const graph = require('@microsoft/microsoft-graph-client');
|
|
9
|
+
const authProviders = require('@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials');
|
|
10
|
+
class MsGraphConnector {
|
|
11
|
+
async ready(connectionConfigs) {
|
|
12
|
+
await Promise.all(connectionConfigs.map(this.connect.bind(this)));
|
|
13
|
+
integration_base_1.ConnectionManager.logger.info('msgraph-connector connections are ready');
|
|
14
|
+
}
|
|
15
|
+
async connect(connection) {
|
|
16
|
+
var { endpoint: uri = 'https://graph.microsoft.com/v1.0', params: { clientId, clientSecret, tenantId, authTenantId, graphUserScopes } } = connection;
|
|
17
|
+
if (!clientId || !clientSecret || !tenantId || !authTenantId) {
|
|
18
|
+
throw new Error('Connection parameters should not be undefined');
|
|
19
|
+
}
|
|
20
|
+
const credential = new azure.ClientSecretCredential(tenantId, clientId, clientSecret);
|
|
21
|
+
const authProvider = new authProviders.TokenCredentialAuthenticationProvider(credential, {
|
|
22
|
+
scopes: ['https://graph.microsoft.com/.default']
|
|
23
|
+
});
|
|
24
|
+
const client = graph.Client.initWithMiddleware({
|
|
25
|
+
authProvider: authProvider
|
|
26
|
+
});
|
|
27
|
+
integration_base_1.ConnectionManager.addConnectionInstance(connection, client);
|
|
28
|
+
integration_base_1.ConnectionManager.logger.info(`msgraph-connector connection(${connection.name}:${connection.endpoint}) is connected`);
|
|
29
|
+
}
|
|
30
|
+
async disconnect(connection) {
|
|
31
|
+
const client = integration_base_1.ConnectionManager.getConnectionInstance(connection);
|
|
32
|
+
// TODO implement how to stop connection
|
|
33
|
+
integration_base_1.ConnectionManager.removeConnectionInstance(connection);
|
|
34
|
+
integration_base_1.ConnectionManager.logger.info(`msgraph-connector connection(${connection.name}) is disconnected`);
|
|
35
|
+
}
|
|
36
|
+
get parameterSpec() {
|
|
37
|
+
/* To get proper settings, refer https://developer.microsoft.com/en-us/graph/quick-start */
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
type: 'string',
|
|
41
|
+
name: 'clientId',
|
|
42
|
+
label: 'client-id'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'string',
|
|
46
|
+
name: 'clientSecret',
|
|
47
|
+
label: 'client-secret'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: 'string',
|
|
51
|
+
name: 'tenantId',
|
|
52
|
+
label: 'tenant-id'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: 'string',
|
|
56
|
+
name: 'authTenantId',
|
|
57
|
+
label: 'auth-tenant-id'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: 'string',
|
|
61
|
+
name: 'graphUserScopes',
|
|
62
|
+
label: 'graph-user-scopes'
|
|
63
|
+
}
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
get taskPrefixes() {
|
|
67
|
+
return ['msgraph'];
|
|
68
|
+
}
|
|
69
|
+
get description() {
|
|
70
|
+
return 'Graph API Connector';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.MsGraphConnector = MsGraphConnector;
|
|
74
|
+
integration_base_1.ConnectionManager.registerConnector('msgraph-connector', new MsGraphConnector());
|
|
75
|
+
//# sourceMappingURL=graph-connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/graph-connector.ts"],"names":[],"mappings":";;;AAAA,mBAAmB;AACnB,gCAA6B;AAE7B,uEAA+E;AAE/E,MAAM,KAAK,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;AACxC,MAAM,KAAK,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAA;AAC1D,MAAM,aAAa,GAAG,OAAO,CAAC,uEAAuE,CAAC,CAAA;AAEtG,MAAa,gBAAgB;IAC3B,KAAK,CAAC,KAAK,CAAC,iBAAiB;QAC3B,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAEjE,oCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAA;IAC1E,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,UAAU;QACtB,IAAI,EACF,QAAQ,EAAE,GAAG,GAAG,kCAAkC,EAClD,MAAM,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,EAC5E,GAAG,UAAU,CAAA;QAEd,IAAI,CAAC,QAAQ,IAAI,CAAC,YAAY,IAAI,CAAC,QAAQ,IAAI,CAAC,YAAY,EAAE;YAC5D,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;SACjE;QAED,MAAM,UAAU,GAAG,IAAI,KAAK,CAAC,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAA;QACrF,MAAM,YAAY,GAAG,IAAI,aAAa,CAAC,qCAAqC,CAAC,UAAU,EAAE;YACvF,MAAM,EAAE,CAAC,sCAAsC,CAAC;SACjD,CAAC,CAAA;QAEF,MAAM,MAAM,GAAG,KAAK,CA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AE,IAAI,gBAAgB,EAAE,CAAC,CAAA","sourcesContent":["/* fetch polyfil */\nimport 'cross-fetch/polyfill'\n\nimport { ConnectionManager, Connector } from '@things-factory/integration-base'\n\nconst azure = require('@azure/identity')\nconst graph = require('@microsoft/microsoft-graph-client')\nconst authProviders = require('@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials')\n\nexport class MsGraphConnector implements Connector {\n async ready(connectionConfigs) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('msgraph-connector connections are ready')\n }\n\n async connect(connection) {\n var {\n endpoint: uri = 'https://graph.microsoft.com/v1.0',\n params: { clientId, clientSecret, tenantId, authTenantId, graphUserScopes }\n } = connection\n\n if (!clientId || !clientSecret || !tenantId || !authTenantId) {\n throw new Error('Connection parameters should not be undefined')\n }\n\n const credential = new azure.ClientSecretCredential(tenantId, clientId, clientSecret)\n const authProvider = new authProviders.TokenCredentialAuthenticationProvider(credential, {\n scopes: ['https://graph.microsoft.com/.default']\n })\n\n const client = graph.Client.initWithMiddleware({\n authProvider: authProvider\n })\n\n ConnectionManager.addConnectionInstance(connection, client)\n\n ConnectionManager.logger.info(\n `msgraph-connector connection(${connection.name}:${connection.endpoint}) is connected`\n )\n }\n\n async disconnect(connection) {\n const client = ConnectionManager.getConnectionInstance(connection)\n // TODO implement how to stop connection\n ConnectionManager.removeConnectionInstance(connection)\n\n ConnectionManager.logger.info(`msgraph-connector connection(${connection.name}) is disconnected`)\n }\n\n get parameterSpec() {\n /* To get proper settings, refer https://developer.microsoft.com/en-us/graph/quick-start */\n return [\n {\n type: 'string',\n name: 'clientId',\n label: 'client-id'\n },\n {\n type: 'string',\n name: 'clientSecret',\n label: 'client-secret'\n },\n {\n type: 'string',\n name: 'tenantId',\n label: 'tenant-id'\n },\n {\n type: 'string',\n name: 'authTenantId',\n label: 'auth-tenant-id'\n },\n {\n type: 'string',\n name: 'graphUserScopes',\n label: 'graph-user-scopes'\n }\n ]\n }\n\n get taskPrefixes() {\n return ['msgraph']\n }\n\n get description() {\n return 'Graph API Connector'\n }\n}\n\nConnectionManager.registerConnector('msgraph-connector', new MsGraphConnector())\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/engine/connector/index.ts"],"names":[],"mappings":";;AAAA,+BAA4B","sourcesContent":["import './msgraph-connector'\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModbusTCPServer = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
6
|
+
const net_1 = tslib_1.__importDefault(require("net"));
|
|
7
|
+
const modbus = tslib_1.__importStar(require("jsmodbus"));
|
|
8
|
+
class ModbusTCPServer {
|
|
9
|
+
async ready(connectionConfigs) {
|
|
10
|
+
await Promise.all(connectionConfigs.map(this.connect));
|
|
11
|
+
integration_base_1.ConnectionManager.logger.info('modbus-tcp-servers are ready');
|
|
12
|
+
}
|
|
13
|
+
async connect(config) {
|
|
14
|
+
var [host = '0.0.0.0', port = 502] = config.endpoint.split(':');
|
|
15
|
+
const netServer = new net_1.default.Server();
|
|
16
|
+
const server = new modbus.server.TCP(netServer);
|
|
17
|
+
netServer.on('error', console.error);
|
|
18
|
+
netServer.listen(port, host);
|
|
19
|
+
/* default client connection */
|
|
20
|
+
const clientSocket = new net_1.default.Socket();
|
|
21
|
+
const client = new modbus.client.TCP(clientSocket);
|
|
22
|
+
clientSocket.on('error', console.error);
|
|
23
|
+
clientSocket.connect({ host: 'localhost', port });
|
|
24
|
+
client['__server__'] = server;
|
|
25
|
+
integration_base_1.ConnectionManager.addConnectionInstance(config, client);
|
|
26
|
+
integration_base_1.ConnectionManager.logger.info(`modbus-tcp-server connection(${config.name}:${config.endpoint}) is connected`);
|
|
27
|
+
}
|
|
28
|
+
async disconnect(connection) {
|
|
29
|
+
var client = integration_base_1.ConnectionManager.removeConnectionInstance(connection);
|
|
30
|
+
var server = client['__server__'];
|
|
31
|
+
client.socket.end();
|
|
32
|
+
server && server._server.close();
|
|
33
|
+
integration_base_1.ConnectionManager.logger.info(`modbus-tcp-server connection(${connection.name}) is disconnected`);
|
|
34
|
+
}
|
|
35
|
+
get parameterSpec() {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.ModbusTCPServer = ModbusTCPServer;
|
|
40
|
+
integration_base_1.ConnectionManager.registerConnector('modbus-tcp-server', new ModbusTCPServer());
|
|
41
|
+
//# sourceMappingURL=modbus-tcp-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modbus-tcp-server.js","sourceRoot":"","sources":["../../../server/engine/connector/modbus-tcp-server.ts"],"names":[],"mappings":";;;;AAAA,uEAA2F;AAC3F,sDAAqB;AACrB,yDAAkC;AAElC,MAAa,eAAe;IAC1B,KAAK,CAAC,KAAK,CAAC,iBAAiB;QAC3B,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;QAEtD,oCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAA;IAC/D,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAM;QAClB,IAAI,CAAC,IAAI,GAAG,SAAS,EAAE,IAAI,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAE/D,MAAM,SAAS,GAAG,IAAI,aAAG,CAAC,MAAM,EAAE,CAAA;QAElC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QAE/C,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;QACpC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAE5B,+BAA+B;QAC/B,MAAM,YAAY,GAAG,IAAI,aAAG,CAAC,MAAM,EAAE,CAAA;QACrC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QAClD,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;QACvC,YAAY,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;QAEjD,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,CAAA;QAE7B,oCAAiB,CAAC,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAEvD,oCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,gCAAgC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,QAAQ,gBAAgB,CAAC,CAAA;IAC/G,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,UAAsB;QACrC,IAAI,MAAM,GAAG,oCAAiB,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAA;QACnE,IAAI,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;QAEjC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAA;QACnB,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;QAEhC,oCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,gCAAgC,UAAU,CAAC,IAAI,mBAAmB,CAAC,CAAA;IACnG,CAAC;IAED,IAAI,aAAa;QACf,OAAO,EAAE,CAAA;IACX,CAAC;CACF;AA3CD,0CA2CC;AAED,oCAAiB,CAAC,iBAAiB,CAAC,mBAAmB,EAAE,IAAI,eAAe,EAAE,CAAC,CAAA","sourcesContent":["import { ConnectionManager, Connector, Connection } from '@things-factory/integration-base'\nimport net from 'net'\nimport * as modbus from 'jsmodbus'\n\nexport class ModbusTCPServer implements Connector {\n async ready(connectionConfigs) {\n await Promise.all(connectionConfigs.map(this.connect))\n\n ConnectionManager.logger.info('modbus-tcp-servers are ready')\n }\n\n async connect(config) {\n var [host = '0.0.0.0', port = 502] = config.endpoint.split(':')\n\n const netServer = new net.Server()\n\n const server = new modbus.server.TCP(netServer)\n\n netServer.on('error', console.error)\n netServer.listen(port, host)\n\n /* default client connection */\n const clientSocket = new net.Socket()\n const client = new modbus.client.TCP(clientSocket)\n clientSocket.on('error', console.error)\n clientSocket.connect({ host: 'localhost', port })\n\n client['__server__'] = server\n\n ConnectionManager.addConnectionInstance(config, client)\n\n ConnectionManager.logger.info(`modbus-tcp-server connection(${config.name}:${config.endpoint}) is connected`)\n }\n\n async disconnect(connection: Connection) {\n var client = ConnectionManager.removeConnectionInstance(connection)\n var server = client['__server__']\n\n client.socket.end()\n server && server._server.close()\n\n ConnectionManager.logger.info(`modbus-tcp-server connection(${connection.name}) is disconnected`)\n }\n\n get parameterSpec() {\n return []\n }\n}\n\nConnectionManager.registerConnector('modbus-tcp-server', new ModbusTCPServer())\n"]}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModbusTCPConnector = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const modbus = tslib_1.__importStar(require("jsmodbus"));
|
|
6
|
+
const net_1 = require("net");
|
|
7
|
+
const p_queue_1 = tslib_1.__importDefault(require("p-queue"));
|
|
8
|
+
const promise_socket_1 = tslib_1.__importDefault(require("promise-socket"));
|
|
9
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
10
|
+
const utils_1 = require("@things-factory/utils");
|
|
11
|
+
class ModbusTCPConnector {
|
|
12
|
+
async ready(connectionConfigs) {
|
|
13
|
+
await Promise.all(connectionConfigs.map(this.connect));
|
|
14
|
+
integration_base_1.ConnectionManager.logger.info('modbus-tcp connections are ready');
|
|
15
|
+
}
|
|
16
|
+
async connect(config) {
|
|
17
|
+
var [host, port = 502] = config.endpoint.split(':');
|
|
18
|
+
var { params } = config;
|
|
19
|
+
var clientSocket = new net_1.Socket();
|
|
20
|
+
var promiseSocket = new promise_socket_1.default(clientSocket);
|
|
21
|
+
var client = new modbus.client.TCP(clientSocket);
|
|
22
|
+
try {
|
|
23
|
+
clientSocket.on('error', console.error);
|
|
24
|
+
await promiseSocket.connect(port, host);
|
|
25
|
+
var queue = new p_queue_1.default({ concurrency: 1 });
|
|
26
|
+
var keepalive = params.keepalive;
|
|
27
|
+
integration_base_1.ConnectionManager.addConnectionInstance(config, {
|
|
28
|
+
readModBus: async function (objectType, address, quantity, { logger }) {
|
|
29
|
+
return await queue.add(async () => {
|
|
30
|
+
while (true) {
|
|
31
|
+
try {
|
|
32
|
+
var response;
|
|
33
|
+
switch (objectType) {
|
|
34
|
+
case 'descrete input':
|
|
35
|
+
response = await client.readDiscreteInputs(address, quantity);
|
|
36
|
+
break;
|
|
37
|
+
case 'input register':
|
|
38
|
+
response = await client.readInputRegisters(address, quantity);
|
|
39
|
+
break;
|
|
40
|
+
case 'holding register':
|
|
41
|
+
response = await client.readHoldingRegisters(address, quantity);
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
response = await client.readCoils(address, quantity);
|
|
45
|
+
}
|
|
46
|
+
var data = response && response.response._body.valuesAsArray.slice(0, quantity);
|
|
47
|
+
logger.info(`${JSON.stringify(data)}`);
|
|
48
|
+
return {
|
|
49
|
+
data
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
logger.error('readModBus command failed.');
|
|
54
|
+
logger.error(e);
|
|
55
|
+
if (keepalive) {
|
|
56
|
+
promiseSocket && promiseSocket.destroy();
|
|
57
|
+
clientSocket = new net_1.Socket();
|
|
58
|
+
promiseSocket = new promise_socket_1.default(clientSocket);
|
|
59
|
+
client = new modbus.client.TCP(clientSocket);
|
|
60
|
+
clientSocket.on('error', console.error);
|
|
61
|
+
promiseSocket.connect(port, host);
|
|
62
|
+
await (0, utils_1.sleep)(1000);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
writeSingleModBus: async function (objectType, address, value, { logger }) {
|
|
72
|
+
return await queue.add(async () => {
|
|
73
|
+
while (true) {
|
|
74
|
+
try {
|
|
75
|
+
var response;
|
|
76
|
+
switch (objectType) {
|
|
77
|
+
case 'holding register':
|
|
78
|
+
await client.writeSingleRegister(address, parseInt(value));
|
|
79
|
+
response = await client.readHoldingRegisters(address, 1);
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
await client.writeSingleCoil(address, !!Number(value));
|
|
83
|
+
response = await client.readCoils(address, 1);
|
|
84
|
+
}
|
|
85
|
+
var data = response && response.response._body.valuesAsArray[0];
|
|
86
|
+
logger.info(data);
|
|
87
|
+
return {
|
|
88
|
+
data
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
logger.error('writeSingleModBus command failed.');
|
|
93
|
+
logger.error(e);
|
|
94
|
+
if (keepalive) {
|
|
95
|
+
promiseSocket && promiseSocket.destroy();
|
|
96
|
+
clientSocket = new net_1.Socket();
|
|
97
|
+
promiseSocket = new promise_socket_1.default(clientSocket);
|
|
98
|
+
client = new modbus.client.TCP(clientSocket);
|
|
99
|
+
clientSocket.on('error', console.error);
|
|
100
|
+
promiseSocket.connect(port, host);
|
|
101
|
+
await (0, utils_1.sleep)(1000);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
throw e;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
close: function () {
|
|
111
|
+
queue.clear();
|
|
112
|
+
keepalive = false;
|
|
113
|
+
promiseSocket.destroy();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
integration_base_1.ConnectionManager.logger.info(`modbus-tcp connection(${config.name}:${config.endpoint}) is connected`);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
integration_base_1.ConnectionManager.logger.info(`modbus-tcp connection(${config.name}:${config.endpoint}) failed to connect`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async disconnect(connection) {
|
|
123
|
+
var { close } = integration_base_1.ConnectionManager.removeConnectionInstance(connection);
|
|
124
|
+
close();
|
|
125
|
+
integration_base_1.ConnectionManager.logger.info(`modbus-tcp connection(${connection.name}) is disconnected`);
|
|
126
|
+
}
|
|
127
|
+
get parameterSpec() {
|
|
128
|
+
return [
|
|
129
|
+
{
|
|
130
|
+
type: 'checkbox',
|
|
131
|
+
name: 'keepalive',
|
|
132
|
+
label: 'keepalive'
|
|
133
|
+
}
|
|
134
|
+
];
|
|
135
|
+
}
|
|
136
|
+
get taskPrefixes() {
|
|
137
|
+
return ['modbus'];
|
|
138
|
+
}
|
|
139
|
+
get help() {
|
|
140
|
+
return 'integration/connector/modbus-tcp';
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.ModbusTCPConnector = ModbusTCPConnector;
|
|
144
|
+
integration_base_1.ConnectionManager.registerConnector('modbus-tcp', new ModbusTCPConnector());
|
|
145
|
+
//# sourceMappingURL=modbus-tcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modbus-tcp.js","sourceRoot":"","sources":["../../../server/engine/connector/modbus-tcp.ts"],"names":[],"mappings":";;;;AAAA,yDAAkC;AAClC,6BAA4B;AAC5B,8DAA4B;AAC5B,4EAA0C;AAE1C,uEAA2F;AAC3F,iDAA6C;AAE7C,MAAa,kBAAkB;IAC7B,KAAK,CAAC,KAAK,CAAC,iBAAiB;QAC3B,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;QAEtD,oCAAiB,C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AE,CAAC,CAAA","sourcesContent":["import * as modbus from 'jsmodbus'\nimport { Socket } from 'net'\nimport PQueue from 'p-queue'\nimport PromiseSocket from 'promise-socket'\n\nimport { Connection, ConnectionManager, Connector } from '@things-factory/integration-base'\nimport { sleep } from '@things-factory/utils'\n\nexport class ModbusTCPConnector implements Connector {\n async ready(connectionConfigs) {\n await Promise.all(connectionConfigs.map(this.connect))\n\n ConnectionManager.logger.info('modbus-tcp connections are ready')\n }\n\n async connect(config) {\n var [host, port = 502] = config.endpoint.split(':')\n var { params } = config\n\n var clientSocket = new Socket()\n var promiseSocket = new PromiseSocket(clientSocket)\n\n var client = new modbus.client.TCP(clientSocket)\n\n try {\n clientSocket.on('error', console.error)\n\n await promiseSocket.connect(port, host)\n\n var queue = new PQueue({ concurrency: 1 })\n var keepalive = params.keepalive\n\n ConnectionManager.addConnectionInstance(config, {\n readModBus: async function (objectType, address, quantity, { logger }) {\n return await queue.add(async () => {\n while (true) {\n try {\n var response\n\n switch (objectType) {\n case 'descrete input':\n response = await client.readDiscreteInputs(address, quantity)\n break\n case 'input register':\n response = await client.readInputRegisters(address, quantity)\n break\n case 'holding register':\n response = await client.readHoldingRegisters(address, quantity)\n break\n default:\n response = await client.readCoils(address, quantity)\n }\n\n var data = response && response.response._body.valuesAsArray.slice(0, quantity)\n logger.info(`${JSON.stringify(data)}`)\n return {\n data\n }\n } catch (e) {\n logger.error('readModBus command failed.')\n logger.error(e)\n\n if (keepalive) {\n promiseSocket && promiseSocket.destroy()\n\n clientSocket = new Socket()\n promiseSocket = new PromiseSocket(clientSocket)\n client = new modbus.client.TCP(clientSocket)\n clientSocket.on('error', console.error)\n promiseSocket.connect(port, host)\n\n await sleep(1000)\n } else {\n throw e\n }\n }\n }\n })\n },\n writeSingleModBus: async function (objectType, address, value, { logger }) {\n return await queue.add(async () => {\n while (true) {\n try {\n var response\n\n switch (objectType) {\n case 'holding register':\n await client.writeSingleRegister(address, parseInt(value))\n response = await client.readHoldingRegisters(address, 1)\n break\n default:\n await client.writeSingleCoil(address, !!Number(value))\n response = await client.readCoils(address, 1)\n }\n\n var data = response && response.response._body.valuesAsArray[0]\n logger.info(data)\n return {\n data\n }\n } catch (e) {\n logger.error('writeSingleModBus command failed.')\n logger.error(e)\n\n if (keepalive) {\n promiseSocket && promiseSocket.destroy()\n\n clientSocket = new Socket()\n promiseSocket = new PromiseSocket(clientSocket)\n client = new modbus.client.TCP(clientSocket)\n clientSocket.on('error', console.error)\n promiseSocket.connect(port, host)\n\n await sleep(1000)\n } else {\n throw e\n }\n }\n }\n })\n },\n close: function () {\n queue.clear()\n keepalive = false\n promiseSocket.destroy()\n }\n })\n\n ConnectionManager.logger.info(`modbus-tcp connection(${config.name}:${config.endpoint}) is connected`)\n } catch (error) {\n ConnectionManager.logger.info(`modbus-tcp connection(${config.name}:${config.endpoint}) failed to connect`)\n }\n }\n\n async disconnect(connection: Connection) {\n var { close } = ConnectionManager.removeConnectionInstance(connection)\n close()\n\n ConnectionManager.logger.info(`modbus-tcp connection(${connection.name}) is disconnected`)\n }\n\n get parameterSpec() {\n return [\n {\n type: 'checkbox',\n name: 'keepalive',\n label: 'keepalive'\n }\n ]\n }\n\n get taskPrefixes() {\n return ['modbus']\n }\n\n get help() {\n return 'integration/connector/modbus-tcp'\n }\n}\n\nConnectionManager.registerConnector('modbus-tcp', new ModbusTCPConnector())\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MsGraphConnector = void 0;
|
|
4
|
+
/* fetch polyfil */
|
|
5
|
+
require("cross-fetch/polyfill");
|
|
6
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
7
|
+
const azure = require('@azure/identity');
|
|
8
|
+
const graph = require('@microsoft/microsoft-graph-client');
|
|
9
|
+
const authProviders = require('@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials');
|
|
10
|
+
class MsGraphConnector {
|
|
11
|
+
async ready(connectionConfigs) {
|
|
12
|
+
await Promise.all(connectionConfigs.map(this.connect.bind(this)));
|
|
13
|
+
integration_base_1.ConnectionManager.logger.info('msgraph-connector connections are ready');
|
|
14
|
+
}
|
|
15
|
+
async connect(connection) {
|
|
16
|
+
var { endpoint: uri = 'https://graph.microsoft.com/v1.0', params: { clientId, clientSecret, tenantId, authTenantId, graphUserScopes } } = connection;
|
|
17
|
+
if (!clientId || !clientSecret || !tenantId || !authTenantId) {
|
|
18
|
+
throw new Error('Connection parameters should not be undefined');
|
|
19
|
+
}
|
|
20
|
+
const credential = new azure.ClientSecretCredential(tenantId, clientId, clientSecret);
|
|
21
|
+
const authProvider = new authProviders.TokenCredentialAuthenticationProvider(credential, {
|
|
22
|
+
scopes: ['https://graph.microsoft.com/.default']
|
|
23
|
+
});
|
|
24
|
+
const client = graph.Client.initWithMiddleware({
|
|
25
|
+
authProvider: authProvider
|
|
26
|
+
});
|
|
27
|
+
integration_base_1.ConnectionManager.addConnectionInstance(connection, client);
|
|
28
|
+
integration_base_1.ConnectionManager.logger.info(`msgraph-connector connection(${connection.name}:${connection.endpoint}) is connected`);
|
|
29
|
+
}
|
|
30
|
+
async disconnect(connection) {
|
|
31
|
+
const client = integration_base_1.ConnectionManager.getConnectionInstance(connection);
|
|
32
|
+
// TODO implement how to stop connection
|
|
33
|
+
integration_base_1.ConnectionManager.removeConnectionInstance(connection);
|
|
34
|
+
integration_base_1.ConnectionManager.logger.info(`msgraph-connector connection(${connection.name}) is disconnected`);
|
|
35
|
+
}
|
|
36
|
+
get parameterSpec() {
|
|
37
|
+
/* To get proper settings, refer https://developer.microsoft.com/en-us/graph/quick-start */
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
type: 'string',
|
|
41
|
+
name: 'clientId',
|
|
42
|
+
label: 'client-id'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'string',
|
|
46
|
+
name: 'clientSecret',
|
|
47
|
+
label: 'client-secret'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: 'string',
|
|
51
|
+
name: 'tenantId',
|
|
52
|
+
label: 'tenant-id'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: 'string',
|
|
56
|
+
name: 'authTenantId',
|
|
57
|
+
label: 'auth-tenant-id'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: 'string',
|
|
61
|
+
name: 'graphUserScopes',
|
|
62
|
+
label: 'graph-user-scopes'
|
|
63
|
+
}
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
get taskPrefixes() {
|
|
67
|
+
return ['msgraph'];
|
|
68
|
+
}
|
|
69
|
+
get description() {
|
|
70
|
+
return 'Graph API Connector';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.MsGraphConnector = MsGraphConnector;
|
|
74
|
+
integration_base_1.ConnectionManager.registerConnector('msgraph-connector', new MsGraphConnector());
|
|
75
|
+
//# sourceMappingURL=msgraph-connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msgraph-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/msgraph-connector.ts"],"names":[],"mappings":";;;AAAA,mBAAmB;AACnB,gCAA6B;AAE7B,uEAA+E;AAE/E,MAAM,KAAK,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;AACxC,MAAM,KAAK,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAA;AAC1D,MAAM,aAAa,GAAG,OAAO,CAAC,uEAAuE,CAAC,CAAA;AAEtG,MAAa,gBAAgB;IAC3B,KAAK,CAAC,KAAK,CAAC,iBAAiB;QAC3B,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAEjE,oCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAA;IAC1E,CAAC;IAED,KAAK,CA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BAChB,KAAK,EAAE,WAAW;aACnB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,cAAc;gBACpB,KAAK,EAAE,eAAe;aACvB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,WAAW;aACnB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,cAAc;gBACpB,KAAK,EAAE,gBAAgB;aACxB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,iBAAiB;gBACvB,KAAK,EAAE,mBAAmB;aAC3B;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,SAAS,CAAC,CAAA;IACpB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,qBAAqB,CAAA;IAC9B,CAAC;CACF;AA/ED,4CA+EC;AAED,oCAAiB,CAAC,iBAAiB,CAAC,mBAAmB,EAAE,IAAI,gBAAgB,EAAE,CAAC,CAAA","sourcesContent":["/* fetch polyfil */\nimport 'cross-fetch/polyfill'\n\nimport { ConnectionManager, Connector } from '@things-factory/integration-base'\n\nconst azure = require('@azure/identity')\nconst graph = require('@microsoft/microsoft-graph-client')\nconst authProviders = require('@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials')\n\nexport class MsGraphConnector implements Connector {\n async ready(connectionConfigs) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('msgraph-connector connections are ready')\n }\n\n async connect(connection) {\n var {\n endpoint: uri = 'https://graph.microsoft.com/v1.0',\n params: { clientId, clientSecret, tenantId, authTenantId, graphUserScopes }\n } = connection\n\n if (!clientId || !clientSecret || !tenantId || !authTenantId) {\n throw new Error('Connection parameters should not be undefined')\n }\n\n const credential = new azure.ClientSecretCredential(tenantId, clientId, clientSecret)\n const authProvider = new authProviders.TokenCredentialAuthenticationProvider(credential, {\n scopes: ['https://graph.microsoft.com/.default']\n })\n\n const client = graph.Client.initWithMiddleware({\n authProvider: authProvider\n })\n\n ConnectionManager.addConnectionInstance(connection, client)\n\n ConnectionManager.logger.info(\n `msgraph-connector connection(${connection.name}:${connection.endpoint}) is connected`\n )\n }\n\n async disconnect(connection) {\n const client = ConnectionManager.getConnectionInstance(connection)\n // TODO implement how to stop connection\n ConnectionManager.removeConnectionInstance(connection)\n\n ConnectionManager.logger.info(`msgraph-connector connection(${connection.name}) is disconnected`)\n }\n\n get parameterSpec() {\n /* To get proper settings, refer https://developer.microsoft.com/en-us/graph/quick-start */\n return [\n {\n type: 'string',\n name: 'clientId',\n label: 'client-id'\n },\n {\n type: 'string',\n name: 'clientSecret',\n label: 'client-secret'\n },\n {\n type: 'string',\n name: 'tenantId',\n label: 'tenant-id'\n },\n {\n type: 'string',\n name: 'authTenantId',\n label: 'auth-tenant-id'\n },\n {\n type: 'string',\n name: 'graphUserScopes',\n label: 'graph-user-scopes'\n }\n ]\n }\n\n get taskPrefixes() {\n return ['msgraph']\n }\n\n get description() {\n return 'Graph API Connector'\n }\n}\n\nConnectionManager.registerConnector('msgraph-connector', new MsGraphConnector())\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/engine/index.ts"],"names":[],"mappings":";;AAAA,uBAAoB;AACpB,kBAAe","sourcesContent":["import './connector'\nimport './task'\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
4
|
+
const integration_base_2 = require("@things-factory/integration-base");
|
|
5
|
+
async function GetUsers(step, context) {
|
|
6
|
+
var { connection: connectionName, params: stepOptions } = step;
|
|
7
|
+
var { select, page = 0, limit = 30, orderby } = stepOptions || {};
|
|
8
|
+
var { domain, data, variables } = context;
|
|
9
|
+
var client = integration_base_2.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
|
|
10
|
+
select || (select = 'displayName,id,mail');
|
|
11
|
+
orderby || (orderby = 'displayName');
|
|
12
|
+
try {
|
|
13
|
+
const result = await (client === null || client === void 0 ? void 0 : client.api('/users').select(select.split(',')).top(limit).orderby(orderby).get());
|
|
14
|
+
return {
|
|
15
|
+
data: result
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
console.error(err);
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
GetUsers.parameterSpec = [
|
|
24
|
+
{
|
|
25
|
+
type: 'string',
|
|
26
|
+
name: 'select',
|
|
27
|
+
label: 'select'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: 'number',
|
|
31
|
+
name: 'page',
|
|
32
|
+
label: 'page'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
type: 'number',
|
|
36
|
+
name: 'limit',
|
|
37
|
+
label: 'limit'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: 'string',
|
|
41
|
+
name: 'orderby',
|
|
42
|
+
label: 'orderby'
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
GetUsers.help = 'integration/msgraph/task/get-users';
|
|
46
|
+
integration_base_1.TaskRegistry.registerTaskHandler('msgraph-get-users', GetUsers);
|
|
47
|
+
//# sourceMappingURL=get-users.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-users.js","sourceRoot":"","sources":["../../../server/engine/task/get-users.ts"],"names":[],"mappings":";;AAAA,uEAA+D;AAC/D,uEAA+E;AAE/E,KAAK,UAAU,QAAQ,CAAC,IAAI,EAAE,OAAO;IACnC,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;IAC9D,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,WAAW,IAAI,EAAE,CAAA;IACjE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IAEzC,IAAI,MAAM,GAAG,oCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAElF,MAAM,KAAN,MAAM,GAAK,qBAAqB,EAAA;IAChC,OAAO,KAAP,OAAO,GAAK,aAAa,EAAA;IAEzB,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,CAAA,CAAA;QAEtG,OAAO;YACL,IAAI,EAAE,MAAM;SACb,CAAA;KACF;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAClB,MAAM,GAAG,CAAA;KACV;AACH,CAAC;AAED,QAAQ,CAAC,aAAa,GAAG;IACvB;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,QAAQ;KAChB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,MAAM;KACd;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;KACf;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB;CACF,CAAA;AACD,QAAQ,CAAC,IAAI,GAAG,oCAAoC,CAAA;AAEpD,+BAAY,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,QAAQ,CAAC,CAAA","sourcesContent":["import { TaskRegistry } from '@things-factory/integration-base'\nimport { ConnectionManager, Connector } from '@things-factory/integration-base'\n\nasync function GetUsers(step, context) {\n var { connection: connectionName, params: stepOptions } = step\n var { select, page = 0, limit = 30, orderby } = stepOptions || {}\n var { domain, data, variables } = context\n\n var client = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n select ||= 'displayName,id,mail'\n orderby ||= 'displayName'\n\n try {\n const result = await client?.api('/users').select(select.split(',')).top(limit).orderby(orderby).get()\n\n return {\n data: result\n }\n } catch (err) {\n console.error(err)\n throw err\n }\n}\n\nGetUsers.parameterSpec = [\n {\n type: 'string',\n name: 'select',\n label: 'select'\n },\n {\n type: 'number',\n name: 'page',\n label: 'page'\n },\n {\n type: 'number',\n name: 'limit',\n label: 'limit'\n },\n {\n type: 'string',\n name: 'orderby',\n label: 'orderby'\n }\n]\nGetUsers.help = 'integration/msgraph/task/get-users'\n\nTaskRegistry.registerTaskHandler('msgraph-get-users', GetUsers)\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/engine/task/index.ts"],"names":[],"mappings":";;AAAA,+BAA4B","sourcesContent":["import './msgraph-get-users'\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
4
|
+
async function modbusRead(step, { logger, domain }) {
|
|
5
|
+
var { connection, params: { objectType = 'coil', address, quantity = 1 } } = step;
|
|
6
|
+
var client = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connection);
|
|
7
|
+
if (!client) {
|
|
8
|
+
throw new Error(`no connection : ${connection}`);
|
|
9
|
+
}
|
|
10
|
+
// NOTICE: Keep the previous codes to track the changes before applying keepalive
|
|
11
|
+
// var response
|
|
12
|
+
// switch (objectType) {
|
|
13
|
+
// case 'descrete input':
|
|
14
|
+
// response = await client.readCoils(address, quantity)
|
|
15
|
+
// break
|
|
16
|
+
// case 'input register':
|
|
17
|
+
// response = await client.readDiscreteInputs(address, quantity)
|
|
18
|
+
// break
|
|
19
|
+
// case 'holding register':
|
|
20
|
+
// response = await client.readHoldingRegisters(address, quantity)
|
|
21
|
+
// break
|
|
22
|
+
// default:
|
|
23
|
+
// response = await client.readCoils(address, quantity)
|
|
24
|
+
// }
|
|
25
|
+
// var data = response && response.response._body.valuesAsArray.slice(0, quantity)
|
|
26
|
+
// logger.info(`${JSON.stringify(data)}`)
|
|
27
|
+
// return {
|
|
28
|
+
// data
|
|
29
|
+
// }
|
|
30
|
+
var { readModBus } = client;
|
|
31
|
+
var content = await readModBus(objectType, address, quantity, { logger });
|
|
32
|
+
return content;
|
|
33
|
+
}
|
|
34
|
+
modbusRead.parameterSpec = [
|
|
35
|
+
{
|
|
36
|
+
type: 'select',
|
|
37
|
+
name: 'objectType',
|
|
38
|
+
label: 'object-type',
|
|
39
|
+
property: {
|
|
40
|
+
options: ['', 'coil', 'descrete input', 'input register', 'holding register']
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: 'number',
|
|
45
|
+
name: 'address',
|
|
46
|
+
label: 'address'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: 'number',
|
|
50
|
+
name: 'quantity',
|
|
51
|
+
label: 'quantity'
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
integration_base_1.TaskRegistry.registerTaskHandler('modbus-read', modbusRead);
|
|
55
|
+
//# sourceMappingURL=modbus-read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modbus-read.js","sourceRoot":"","sources":["../../../server/engine/task/modbus-read.ts"],"names":[],"mappings":";;AAAA,uEAAkF;AAElF,KAAK,UAAU,UAAU,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;IAChD,IAAI,EACF,UAAU,EACV,MAAM,EAAE,EAAE,UAAU,GAAG,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,CAAC,EAAE,EACvD,GAAG,IAAI,CAAA;IAER,IAAI,MAAM,GAAG,oCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAC9E,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,mBAAmB,UAAU,EAAE,CAAC,CAAA;KACjD;IAED,iFAAiF;IACjF,iBAAiB;IAEjB,0BAA0B;IAC1B,6BAA6B;IAC7B,6DAA6D;IAC7D,cAAc;IACd,6BAA6B;IAC7B,sEAAsE;IACtE,cAAc;IACd,+BAA+B;IAC/B,wEAAwE;IACxE,cAAc;IACd,eAAe;IACf,6DAA6D;IAC7D,MAAM;IAEN,oFAAoF;IACpF,2CAA2C;IAE3C,aAAa;IACb,WAAW;IACX,MAAM;IAEN,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;IAC3B,IAAI,OAAO,GAAG,MAAM,UAAU,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;IACzE,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,UAAU,CAAC,aAAa,GAAG;IACzB;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,aAAa;QACpB,QAAQ,EAAE;YACR,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,CAAC;SAC9E;KACF;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;KAClB;CACF,CAAA;AAED,+BAAY,CAAC,mBAAmB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAA","sourcesContent":["import { ConnectionManager, TaskRegistry } from '@things-factory/integration-base'\n\nasync function modbusRead(step, { logger, domain }) {\n var {\n connection,\n params: { objectType = 'coil', address, quantity = 1 }\n } = step\n\n var client = ConnectionManager.getConnectionInstanceByName(domain, connection)\n if (!client) {\n throw new Error(`no connection : ${connection}`)\n }\n\n // NOTICE: Keep the previous codes to track the changes before applying keepalive\n // var response\n\n // switch (objectType) {\n // case 'descrete input':\n // response = await client.readCoils(address, quantity)\n // break\n // case 'input register':\n // response = await client.readDiscreteInputs(address, quantity)\n // break\n // case 'holding register':\n // response = await client.readHoldingRegisters(address, quantity)\n // break\n // default:\n // response = await client.readCoils(address, quantity)\n // }\n\n // var data = response && response.response._body.valuesAsArray.slice(0, quantity)\n // logger.info(`${JSON.stringify(data)}`)\n\n // return {\n // data\n // }\n\n var { readModBus } = client\n var content = await readModBus(objectType, address, quantity, { logger })\n return content\n}\n\nmodbusRead.parameterSpec = [\n {\n type: 'select',\n name: 'objectType',\n label: 'object-type',\n property: {\n options: ['', 'coil', 'descrete input', 'input register', 'holding register']\n }\n },\n {\n type: 'number',\n name: 'address',\n label: 'address'\n },\n {\n type: 'number',\n name: 'quantity',\n label: 'quantity'\n }\n]\n\nTaskRegistry.registerTaskHandler('modbus-read', modbusRead)\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
4
|
+
async function modbusWriteSingle(step, { logger, domain }) {
|
|
5
|
+
var { connection, params: { objectType = 'coil', address, value } } = step;
|
|
6
|
+
var client = integration_base_1.ConnectionManager.getConnectionInstanceByName(domain, connection);
|
|
7
|
+
if (!client) {
|
|
8
|
+
throw new Error(`no connection : ${connection}`);
|
|
9
|
+
}
|
|
10
|
+
// NOTICE: Keep the previous codes to track the changes before applying keepalive
|
|
11
|
+
// var response
|
|
12
|
+
// switch (objectType) {
|
|
13
|
+
// case 'holding register':
|
|
14
|
+
// await client.writeSingleRegister(address, parseInt(value))
|
|
15
|
+
// response = await client.readHoldingRegisters(address, 1)
|
|
16
|
+
// break
|
|
17
|
+
// default:
|
|
18
|
+
// await client.writeSingleCoil(address, !!value)
|
|
19
|
+
// response = await client.readCoils(address, 1)
|
|
20
|
+
// }
|
|
21
|
+
// var data = response && response.response._body.valuesAsArray[0]
|
|
22
|
+
// logger.info(data)
|
|
23
|
+
// return {
|
|
24
|
+
// data
|
|
25
|
+
// }
|
|
26
|
+
var { writeSingleModBus } = client;
|
|
27
|
+
var content = await writeSingleModBus(objectType, address, value, { logger });
|
|
28
|
+
return content;
|
|
29
|
+
}
|
|
30
|
+
modbusWriteSingle.parameterSpec = [
|
|
31
|
+
{
|
|
32
|
+
type: 'select',
|
|
33
|
+
name: 'objectType',
|
|
34
|
+
label: 'object-type',
|
|
35
|
+
property: {
|
|
36
|
+
options: ['', 'coil', 'holding register']
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: 'number',
|
|
41
|
+
name: 'address',
|
|
42
|
+
label: 'address'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'number',
|
|
46
|
+
name: 'value',
|
|
47
|
+
label: 'value'
|
|
48
|
+
}
|
|
49
|
+
];
|
|
50
|
+
integration_base_1.TaskRegistry.registerTaskHandler('modbus-write-single', modbusWriteSingle);
|
|
51
|
+
//# sourceMappingURL=modbus-write-single.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modbus-write-single.js","sourceRoot":"","sources":["../../../server/engine/task/modbus-write-single.ts"],"names":[],"mappings":";;AAAA,uEAAkF;AAElF,KAAK,UAAU,iBAAiB,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;IACvD,IAAI,EACF,UAAU,EACV,MAAM,EAAE,EAAE,UAAU,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,EAChD,GAAG,IAAI,CAAA;IAER,IAAI,MAAM,GAAG,oCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAC9E,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,mBAAmB,UAAU,EAAE,CAAC,CAAA;KACjD;IAED,iFAAiF;IACjF,iBAAiB;IAEjB,0BAA0B;IAC1B,+BAA+B;IAC/B,mEAAmE;IACnE,iEAAiE;IACjE,cAAc;IACd,eAAe;IACf,uDAAuD;IACvD,sDAAsD;IACtD,MAAM;IAEN,oEAAoE;IACpE,sBAAsB;IAEtB,aAAa;IACb,WAAW;IACX,MAAM;IAEN,IAAI,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAA;IAClC,IAAI,OAAO,GAAG,MAAM,iBAAiB,CAAC,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;IAC7E,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,iBAAiB,CAAC,aAAa,GAAG;IAChC;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,aAAa;QACpB,QAAQ,EAAE;YACR,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,kBAAkB,CAAC;SAC1C;KACF;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;KACf;CACF,CAAA;AAED,+BAAY,CAAC,mBAAmB,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,CAAA","sourcesContent":["import { ConnectionManager, TaskRegistry } from '@things-factory/integration-base'\n\nasync function modbusWriteSingle(step, { logger, domain }) {\n var {\n connection,\n params: { objectType = 'coil', address, value }\n } = step\n\n var client = ConnectionManager.getConnectionInstanceByName(domain, connection)\n if (!client) {\n throw new Error(`no connection : ${connection}`)\n }\n\n // NOTICE: Keep the previous codes to track the changes before applying keepalive\n // var response\n\n // switch (objectType) {\n // case 'holding register':\n // await client.writeSingleRegister(address, parseInt(value))\n // response = await client.readHoldingRegisters(address, 1)\n // break\n // default:\n // await client.writeSingleCoil(address, !!value)\n // response = await client.readCoils(address, 1)\n // }\n\n // var data = response && response.response._body.valuesAsArray[0]\n // logger.info(data)\n\n // return {\n // data\n // }\n\n var { writeSingleModBus } = client\n var content = await writeSingleModBus(objectType, address, value, { logger })\n return content\n}\n\nmodbusWriteSingle.parameterSpec = [\n {\n type: 'select',\n name: 'objectType',\n label: 'object-type',\n property: {\n options: ['', 'coil', 'holding register']\n }\n },\n {\n type: 'number',\n name: 'address',\n label: 'address'\n },\n {\n type: 'number',\n name: 'value',\n label: 'value'\n }\n]\n\nTaskRegistry.registerTaskHandler('modbus-write-single', modbusWriteSingle)\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
4
|
+
const integration_base_2 = require("@things-factory/integration-base");
|
|
5
|
+
async function MsGraphGetUsers(step, context) {
|
|
6
|
+
var { connection: connectionName, params: stepOptions } = step;
|
|
7
|
+
var { select, page = 0, limit = 30, orderby } = stepOptions || {};
|
|
8
|
+
var { domain, data, variables } = context;
|
|
9
|
+
var client = integration_base_2.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
|
|
10
|
+
select || (select = 'displayName,id,mail');
|
|
11
|
+
orderby || (orderby = 'displayName');
|
|
12
|
+
const result = await (client === null || client === void 0 ? void 0 : client.api('/users').select(select.split(',')).top(limit).orderby(orderby).get());
|
|
13
|
+
return {
|
|
14
|
+
data: result
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
MsGraphGetUsers.parameterSpec = [
|
|
18
|
+
{
|
|
19
|
+
type: 'string',
|
|
20
|
+
name: 'select',
|
|
21
|
+
label: 'select'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: 'number',
|
|
25
|
+
name: 'page',
|
|
26
|
+
label: 'page'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: 'number',
|
|
30
|
+
name: 'limit',
|
|
31
|
+
label: 'limit'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: 'string',
|
|
35
|
+
name: 'orderby',
|
|
36
|
+
label: 'orderby'
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
MsGraphGetUsers.help = 'integration/msgraph/task/get-users';
|
|
40
|
+
integration_base_1.TaskRegistry.registerTaskHandler('msgraph-get-users', MsGraphGetUsers);
|
|
41
|
+
//# sourceMappingURL=msgraph-get-users.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msgraph-get-users.js","sourceRoot":"","sources":["../../../server/engine/task/msgraph-get-users.ts"],"names":[],"mappings":";;AAAA,uEAA+D;AAC/D,uEAAoE;AAEpE,KAAK,UAAU,eAAe,CAAC,IAAI,EAAE,OAAO;IAC1C,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;IAC9D,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,WAAW,IAAI,EAAE,CAAA;IACjE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IAEzC,IAAI,MAAM,GAAG,oCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAElF,MAAM,KAAN,MAAM,GAAK,qBAAqB,EAAA;IAChC,OAAO,KAAP,OAAO,GAAK,aAAa,EAAA;IAEzB,MAAM,MAAM,GAAG,MAAM,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,CAAA,CAAA;IAEtG,OAAO;QACL,IAAI,EAAE,MAAM;KACb,CAAA;AACH,CAAC;AAED,eAAe,CAAC,aAAa,GAAG;IAC9B;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,QAAQ;KAChB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,MAAM;KACd;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;KACf;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB;CACF,CAAA;AACD,eAAe,CAAC,IAAI,GAAG,oCAAoC,CAAA;AAE3D,+BAAY,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAA","sourcesContent":["import { TaskRegistry } from '@things-factory/integration-base'\nimport { ConnectionManager } from '@things-factory/integration-base'\n\nasync function MsGraphGetUsers(step, context) {\n var { connection: connectionName, params: stepOptions } = step\n var { select, page = 0, limit = 30, orderby } = stepOptions || {}\n var { domain, data, variables } = context\n\n var client = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n select ||= 'displayName,id,mail'\n orderby ||= 'displayName'\n\n const result = await client?.api('/users').select(select.split(',')).top(limit).orderby(orderby).get()\n\n return {\n data: result\n }\n}\n\nMsGraphGetUsers.parameterSpec = [\n {\n type: 'string',\n name: 'select',\n label: 'select'\n },\n {\n type: 'number',\n name: 'page',\n label: 'page'\n },\n {\n type: 'number',\n name: 'limit',\n label: 'limit'\n },\n {\n type: 'string',\n name: 'orderby',\n label: 'orderby'\n }\n]\nMsGraphGetUsers.help = 'integration/msgraph/task/get-users'\n\nTaskRegistry.registerTaskHandler('msgraph-get-users', MsGraphGetUsers)\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;AAAA,oBAAiB","sourcesContent":["import './engine'\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"program":{"fileNames":["../../../node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../../node_modules/tslib/tslib.d.ts","../server/engine/connector/msgraph-connector.ts","../server/engine/connector/index.ts","../server/engine/task/msgraph-get-users.ts","../server/engine/task/index.ts","../server/engine/index.ts","../server/index.ts","../../../node_modules/@types/node/assert.d.ts","../../../node_modules/@types/node/assert/strict.d.ts","../../../node_modules/@types/node/globals.d.ts","../../../node_modules/@types/node/async_hooks.d.ts","../../../node_modules/@types/node/buffer.d.ts","../../../node_modules/@types/node/child_process.d.ts","../../../node_modules/@types/node/cluster.d.ts","../../../node_modules/@types/node/console.d.ts","../../../node_modules/@types/node/constants.d.ts","../../../node_modules/@types/node/crypto.d.ts","../../../node_modules/@types/node/dgram.d.ts","../../../node_modules/@types/node/diagnostics_channel.d.ts","../../../node_modules/@types/node/dns.d.ts","../../../node_modules/@types/node/dns/promises.d.ts","../../../node_modules/@types/node/domain.d.ts","../../../node_modules/@types/node/dom-events.d.ts","../../../node_modules/@types/node/events.d.ts","../../../node_modules/@types/node/fs.d.ts","../../../node_modules/@types/node/fs/promises.d.ts","../../../node_modules/@types/node/http.d.ts","../../../node_modules/@types/node/http2.d.ts","../../../node_modules/@types/node/https.d.ts","../../../node_modules/@types/node/inspector.d.ts","../../../node_modules/@types/node/module.d.ts","../../../node_modules/@types/node/net.d.ts","../../../node_modules/@types/node/os.d.ts","../../../node_modules/@types/node/path.d.ts","../../../node_modules/@types/node/perf_hooks.d.ts","../../../node_modules/@types/node/process.d.ts","../../../node_modules/@types/node/punycode.d.ts","../../../node_modules/@types/node/querystring.d.ts","../../../node_modules/@types/node/readline.d.ts","../../../node_modules/@types/node/readline/promises.d.ts","../../../node_modules/@types/node/repl.d.ts","../../../node_modules/@types/node/stream.d.ts","../../../node_modules/@types/node/stream/promises.d.ts","../../../node_modules/@types/node/stream/consumers.d.ts","../../../node_modules/@types/node/stream/web.d.ts","../../../node_modules/@types/node/string_decoder.d.ts","../../../node_modules/@types/node/test.d.ts","../../../node_modules/@types/node/timers.d.ts","../../../node_modules/@types/node/timers/promises.d.ts","../../../node_modules/@types/node/tls.d.ts","../../../node_modules/@types/node/trace_events.d.ts","../../../node_modules/@types/node/tty.d.ts","../../../node_modules/@types/node/url.d.ts","../../../node_modules/@types/node/util.d.ts","../../../node_modules/@types/node/v8.d.ts","../../../node_modules/@types/node/vm.d.ts","../../../node_modules/@types/node/wasi.d.ts","../../../node_modules/@types/node/worker_threads.d.ts","../../../node_modules/@types/node/zlib.d.ts","../../../node_modules/@types/node/globals.global.d.ts","../../../node_modules/@types/node/index.d.ts","../../../node_modules/@jest/expect-utils/build/index.d.ts","../../../node_modules/chalk/index.d.ts","../../../node_modules/@sinclair/typebox/typebox.d.ts","../../../node_modules/@jest/schemas/build/index.d.ts","../../../node_modules/pretty-format/build/index.d.ts","../../../node_modules/jest-diff/build/index.d.ts","../../../node_modules/jest-matcher-utils/build/index.d.ts","../../../node_modules/expect/build/index.d.ts","../../../node_modules/@types/jest/index.d.ts"],"fileInfos":[{"version":"8730f4bf322026ff5229336391a18bcaa1f94d4f82416c8b2f3954e2ccaae2ba","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","4b421cbfb3a38a27c279dec1e9112c3d1da296f77a1a85ddadf7e7a425d45d18","1fc5ab7a764205c68fa10d381b08417795fc73111d6dd16b5b1ed36badb743d9",{"version":"3aafcb693fe5b5c3bd277bd4c3a617b53db474fe498fc5df067c5603b1eebde7","affectsGlobalScope":true},{"version":"f3d4da15233e593eacb3965cde7960f3fddf5878528d882bcedd5cbaba0193c7","affectsGlobalScope":true},{"version":"adb996790133eb33b33aadb9c09f15c2c575e71fb57a62de8bf74dbf59ec7dfb","affectsGlobalScope":true},{"version":"8cc8c5a3bac513368b0157f3d8b31cfdcfe78b56d3724f30f80ed9715e404af8","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"5f406584aef28a331c36523df688ca3650288d14f39c5d2e555c95f0d2ff8f6f","affectsGlobalScope":true},{"version":"22f230e544b35349cfb3bd9110b6ef37b41c6d6c43c3314a31bd0d9652fcec72","affectsGlobalScope":true},{"version":"7ea0b55f6b315cf9ac2ad622b0a7813315bb6e97bf4bb3fbf8f8affbca7dc695","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"eb26de841c52236d8222f87e9e6a235332e0788af8c87a71e9e210314300410a","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"81cac4cbc92c0c839c70f8ffb94eb61e2d32dc1c3cf6d95844ca099463cf37ea","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"5e5e095c4470c8bab227dbbc61374878ecead104c74ab9960d3adcccfee23205","affectsGlobalScope":true},{"version":"09aa50414b80c023553090e2f53827f007a301bc34b0495bfb2c3c08ab9ad1eb","affectsGlobalScope":true},{"version":"d7f680a43f8cd12a6b6122c07c54ba40952b0c8aa140dcfcf32eb9e6cb028596","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"2768ef564cfc0689a1b76106c421a2909bdff0acbe87da010785adab80efdd5c","affectsGlobalScope":true},{"version":"b248e32ca52e8f5571390a4142558ae4f203ae2f94d5bac38a3084d529ef4e58","affectsGlobalScope":true},{"version":"52d1bb7ab7a3306fd0375c8bff560feed26ed676a5b0457fa8027b563aecb9a4","affectsGlobalScope":true},"f1c9fe42b65437a61104e601eb298c5c859fb522b483f1bdb700eed67a16f980",{"version":"a70b5a5e59df49ceabf69a15fbabd233254e26bbb8f491b6eca939b74f1f62e3","signature":"0444dfaad391b0243e348dcdd2892fc5e0e7e519b7057207f3fd21a65343cb13"},{"version":"00b4e1983d9ff72f3e1a97a478b9387f9d2067da0b243fff7e46a85eca675e3b","signature":"55a6c867597d9b9f19eeecc4a9b1d00a76166cffe084179670e525d3586cef02"},{"version":"c6274c382111479dfe74a9fa7d9047e460d968e019148d7fbe9cf0e112445a93","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"60ed8d5ef4a0c116adb4d453dee5d57c6add800821a7f2cdba587168eca2403e","signature":"8d902a3e49c1e50f4caa18f36a20078ccdea62dba8c5dea57b009b7d6447f00a"},{"version":"8547694bbf35e324d5bb64215ae218ab372807c759be08f9ce27a8adfc9af9fb","signature":"38512aa59dd75b54e41dac605228d3a48ba7690493a1457f15dfada785d35b3d"},"336b6d64b4cff6c2e09100b496e9870743d9c8005e718c18e6200bce7ec2975c","7e771891adaa85b690266bc37bd6eb43bc57eecc4b54693ead36467e7369952a","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"57b6cb95756d1fe3bfeb20205de27b0c5406e4a86e130c6dfa6bd92af641e09d","affectsGlobalScope":true},"11e2d554398d2bd460e7d06b2fa5827a297c8acfbe00b4f894a224ac0862857f",{"version":"e193e634a99c9c1d71f1c6e4e1567a4a73584328d21ea02dd5cddbaad6693f61","affectsGlobalScope":true},"374ca798f244e464346f14301dc2a8b4b111af1a83b49fffef5906c338a1f922","5a94487653355b56018122d92392beb2e5f4a6c63ba5cef83bbe1c99775ef713",{"version":"d5135ad93b33adcce80b18f8065087934cdc1730d63db58562edcf017e1aad9b","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","e596c9bb2f29a2699fdd4ae89139612652245192f67f45617c5a4b20832aaae9","bb9c4ffa5e6290c6980b63c815cdd1625876dadb2efaf77edbe82984be93e55e","1cdcfc1f624d6c08aa12c73935f6e13f095919cd99edf95752951796eb225729","216717f17c095cde1dc19375e1ab3af0a4a485355860c077a4f9d6ea59fab5b5","14b5aa23c5d0ae1907bc696ac7b6915d88f7d85799cc0dc2dcf98fbce2c5a67c","5c439dafdc09abe4d6c260a96b822fa0ba5be7203c71a63ab1f1423cd9e838ea",{"version":"6b526a5ec4a401ca7c26cfe6a48e641d8f30af76673bad3b06a1b4504594a960","affectsGlobalScope":true},{"version":"816ad2e607a96de5bcac7d437f843f5afd8957f1fa5eefa6bba8e4ed7ca8fd84","affectsGlobalScope":true},"80473bd0dd90ca1e166514c2dfead9d5803f9c51418864ca35abbeec6e6847e1","1c84b46267610a34028edfd0d035509341751262bac1062857f3c8df7aff7153","e6c86d83bd526c8bdb5d0bf935b8e72ce983763d600743f74d812fdf4abf4df6","a3d541d303ee505053f5dcbf9fafb65cac3d5631037501cd616195863a6c5740","8d3c583a07e0c37e876908c2d5da575019f689df8d9fa4c081d99119d53dba22","2c828a5405191d006115ab34e191b8474bc6c86ffdc401d1a9864b1b6e088a58",{"version":"e630e5528e899219ae319e83bef54bf3bcb91b01d76861ecf881e8e614b167f0","affectsGlobalScope":true},"bcebb922784739bdb34c18ee51095d25a92b560c78ccd2eaacd6bd00f7443d83","7ee6ed878c4528215c82b664fe0cfe80e8b4da6c0d4cc80869367868774db8b1","b0973c3cbcdc59b37bf477731d468696ecaf442593ec51bab497a613a580fe30",{"version":"4989e92ba5b69b182d2caaea6295af52b7dc73a4f7a2e336a676722884e7139d","affectsGlobalScope":true},{"version":"0715e4cd28ad471b2a93f3e552ff51a3ae423417a01a10aa1d3bc7c6b95059d6","affectsGlobalScope":true},"5153a2fd150e46ce57bb3f8db1318d33f6ad3261ed70ceeff92281c0608c74a3","210d54cd652ec0fec8c8916e4af59bb341065576ecda039842f9ffb2e908507c","36b03690b628eab08703d63f04eaa89c5df202e5f1edf3989f13ad389cd2c091","0effadd232a20498b11308058e334d3339cc5bf8c4c858393e38d9d4c0013dcf","25846d43937c672bab7e8195f3d881f93495df712ee901860effc109918938cc","7d55d78cd47cf5280643b53434b16c2d9d11d144126932759fbdd51da525eec4","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff","69ee23dd0d215b09907ad30d23f88b7790c93329d1faf31d7835552a10cf7cbf","44b8b584a338b190a59f4f6929d072431950c7bd92ec2694821c11bce180c8a5","23b89798789dffbd437c0c423f5d02d11f9736aea73d6abf16db4f812ff36eda","f69ff39996a61a0dd10f4bce73272b52e8024a4d58b13ab32bf4712909d0a2b7",{"version":"3c4ba1dd9b12ffa284b565063108f2f031d150ea15b8fafbdc17f5d2a07251f3","affectsGlobalScope":true},"e10177274a35a9d07c825615340b2fcde2f610f53f3fb40269fd196b4288dda6","c4577fb855ca259bdbf3ea663ca73988ce5f84251a92b4aef80a1f4122b6f98e","3c13ef48634e7b5012fcf7e8fce7496352c2d779a7201389ca96a2a81ee4314d","5d0a25ec910fa36595f85a67ac992d7a53dd4064a1ba6aea1c9f14ab73a023f2",{"version":"f0900cd5d00fe1263ff41201fb8073dbeb984397e4af3b8002a5c207a30bdc33","affectsGlobalScope":true},{"version":"ff07a9a03c65732ccc59b3c65bc584173da093bd563a6565411c01f5703bd3cb","affectsGlobalScope":true},"6de4a219df57d2b27274d59b67708f13c2cbf7ed211abe57d8f9ab8b25cde776","0fe8985a28f82c450a04a6edf1279d7181c0893f37da7d2a27f8efd4fd5edb03","e59a892d87e72733e2a9ca21611b9beb52977be2696c7ba4b216cbbb9a48f5aa",{"version":"da26af7362f53d122283bc69fed862b9a9fe27e01bc6a69d1d682e0e5a4df3e6","affectsGlobalScope":true},"8a300fa9b698845a1f9c41ecbe2c5966634582a8e2020d51abcace9b55aa959e",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"d8d555f3d607ecaa18d55de6995ea8f206342ecc93305919eac945c7c78c78c6","6c1e688f95fcaf53b1e41c0fdadf2c1cfc96fa924eaf7f9fdb60f96deb0a4986","0d14fa22c41fdc7277e6f71473b20ebc07f40f00e38875142335d5b63cdfc9d2","db25694be959314fd1e868d72e567746db1db9e2001fae545d12d2a8c1bba1b8","43883cf3635bb1846cbdc6c363787b76227677388c74f7313e3f0edb380840fa","2d47012580f859dae201d2eef898a416bdae719dffc087dfd06aefe3de2f9c8d","3e70a7e67c2cb16f8cd49097360c0309fe9d1e3210ff9222e9dac1f8df9d4fb6","ab68d2a3e3e8767c3fba8f80de099a1cfc18c0de79e42cb02ae66e22dfe14a66","2cec1a31729b9b01e9294c33fc9425d336eff067282809761ad2e74425d6d2a5",{"version":"458e2fd1185e659cb800ef68d01ef77de70dcab8860bedf6d94eaebe736751f1","affectsGlobalScope":true}],"options":{"allowSyntheticDefaultImports":true,"declaration":false,"emitDecoratorMetadata":true,"esModuleInterop":true,"experimentalDecorators":true,"importHelpers":true,"inlineSources":true,"module":1,"noEmitOnError":true,"noImplicitAny":false,"outDir":"./","skipLibCheck":true,"sourceMap":true,"strict":false,"target":4,"useDefineForClassFields":false},"fileIdsList":[[97],[97,107],[97,109,112],[51,97],[54,97],[55,60,88,97],[56,67,68,75,85,96,97],[56,57,67,75,97],[58,97],[59,60,68,76,97],[60,85,93,97],[61,63,67,75,97],[62,97],[63,64,97],[67,97],[65,67,97],[67,68,69,85,96,97],[67,68,69,82,85,88,97],[97,101],[63,70,75,85,96,97],[67,68,70,71,75,85,93,96,97],[70,72,85,93,96,97],[51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103],[67,73,97],[74,96,97],[63,67,75,85,97],[76,97],[77,97],[54,78,97],[79,95,97,101],[80,97],[81,97],[67,82,83,97],[82,84,97,99],[55,67,85,86,87,88,97],[55,85,87,97],[85,86,97],[88,97],[89,97],[67,91,92,97],[91,92,97],[60,75,85,93,97],[94,97],[75,95,97],[55,70,81,96,97],[60,97],[85,97,98],[97,99],[97,100],[55,60,67,69,78,85,96,97,99,101],[85,97,102],[97,105,111],[97,109],[97,106,110],[97,108],[44,45,97],[44,97],[44,46,48,97],[44,47,97],[44,49,97],[45],[46,48],[47]],"referencedMap":[[105,1],[108,2],[107,1],[113,3],[51,4],[52,4],[54,5],[55,6],[56,7],[57,8],[58,9],[59,10],[60,11],[61,12],[62,13],[63,14],[64,14],[66,15],[65,16],[67,15],[68,17],[69,18],[53,19],[103,1],[70,20],[71,21],[72,22],[104,23],[73,24],[74,25],[75,26],[76,27],[77,28],[78,29],[79,30],[80,31],[81,32],[82,33],[83,33],[84,34],[85,35],[87,36],[86,37],[88,38],[89,39],[90,1],[91,40],[92,41],[93,42],[94,43],[95,44],[96,45],[97,46],[98,47],[99,48],[100,49],[101,50],[102,51],[106,1],[112,52],[110,53],[111,54],[109,55],[44,1],[8,1],[9,1],[11,1],[10,1],[2,1],[12,1],[13,1],[14,1],[15,1],[16,1],[17,1],[18,1],[19,1],[3,1],[4,1],[23,1],[20,1],[21,1],[22,1],[24,1],[25,1],[26,1],[5,1],[27,1],[28,1],[29,1],[30,1],[6,1],[34,1],[31,1],[32,1],[33,1],[35,1],[7,1],[36,1],[41,1],[42,1],[37,1],[38,1],[39,1],[40,1],[1,1],[43,1],[46,56],[45,57],[49,58],[48,59],[47,57],[50,60]],"exportedModulesMap":[[105,1],[108,2],[107,1],[113,3],[51,4],[52,4],[54,5],[55,6],[56,7],[57,8],[58,9],[59,10],[60,11],[61,12],[62,13],[63,14],[64,14],[66,15],[65,16],[67,15],[68,17],[69,18],[53,19],[103,1],[70,20],[71,21],[72,22],[104,23],[73,24],[74,25],[75,26],[76,27],[77,28],[78,29],[79,30],[80,31],[81,32],[82,33],[83,33],[84,34],[85,35],[87,36],[86,37],[88,38],[89,39],[90,1],[91,40],[92,41],[93,42],[94,43],[95,44],[96,45],[97,46],[98,47],[99,48],[100,49],[101,50],[102,51],[106,1],[112,52],[110,53],[111,54],[109,55],[44,1],[8,1],[9,1],[11,1],[10,1],[2,1],[12,1],[13,1],[14,1],[15,1],[16,1],[17,1],[18,1],[19,1],[3,1],[4,1],[23,1],[20,1],[21,1],[22,1],[24,1],[25,1],[26,1],[5,1],[27,1],[28,1],[29,1],[30,1],[6,1],[34,1],[31,1],[32,1],[33,1],[35,1],[7,1],[36,1],[41,1],[42,1],[37,1],[38,1],[39,1],[40,1],[1,1],[43,1],[46,61],[49,62],[48,63],[50,60]],"semanticDiagnosticsPerFile":[105,108,107,113,51,52,54,55,56,57,58,59,60,61,62,63,64,66,65,67,68,69,53,103,70,71,72,104,73,74,75,76,77,78,79,80,81,82,83,84,85,87,86,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,106,112,110,111,109,44,8,9,11,10,2,12,13,14,15,16,17,18,19,3,4,23,20,21,22,24,25,26,5,27,28,29,30,6,34,31,32,33,35,7,36,41,42,37,38,39,40,1,43,46,45,49,48,47,50]},"version":"4.9.5"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@things-factory/integration-msgraph",
|
|
3
|
+
"version": "6.0.42",
|
|
4
|
+
"main": "dist-server/index.js",
|
|
5
|
+
"browser": "client/index.js",
|
|
6
|
+
"things-factory": true,
|
|
7
|
+
"author": "heartyoh <heartyoh@hatiolab.com>",
|
|
8
|
+
"description": "Module to provide Microsoft graph connection on integration engine",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public",
|
|
11
|
+
"@things-factory:registry": "https://registry.npmjs.org"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/hatiolab/things-factory.git",
|
|
16
|
+
"directory": "packages/integration-msgraph"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc --p tsconfig.json",
|
|
20
|
+
"build:server": "npm run clean:server && tsc",
|
|
21
|
+
"clean:server": "rm -rf dist-server",
|
|
22
|
+
"clean": "npm run clean:server"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@azure/identity": "^3.1.3",
|
|
26
|
+
"@microsoft/microsoft-graph-client": "^3.0.5",
|
|
27
|
+
"@things-factory/integration-base": "^6.0.34",
|
|
28
|
+
"cross-fetch": "^3.0.4"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "01c352d388f5c899aa3f662565e8dbb273c51104"
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './msgraph-connector'
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/* fetch polyfil */
|
|
2
|
+
import 'cross-fetch/polyfill'
|
|
3
|
+
|
|
4
|
+
import { ConnectionManager, Connector } from '@things-factory/integration-base'
|
|
5
|
+
|
|
6
|
+
const azure = require('@azure/identity')
|
|
7
|
+
const graph = require('@microsoft/microsoft-graph-client')
|
|
8
|
+
const authProviders = require('@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials')
|
|
9
|
+
|
|
10
|
+
export class MsGraphConnector implements Connector {
|
|
11
|
+
async ready(connectionConfigs) {
|
|
12
|
+
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
|
13
|
+
|
|
14
|
+
ConnectionManager.logger.info('msgraph-connector connections are ready')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async connect(connection) {
|
|
18
|
+
var {
|
|
19
|
+
endpoint: uri = 'https://graph.microsoft.com/v1.0',
|
|
20
|
+
params: { clientId, clientSecret, tenantId, authTenantId, graphUserScopes }
|
|
21
|
+
} = connection
|
|
22
|
+
|
|
23
|
+
if (!clientId || !clientSecret || !tenantId || !authTenantId) {
|
|
24
|
+
throw new Error('Connection parameters should not be undefined')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const credential = new azure.ClientSecretCredential(tenantId, clientId, clientSecret)
|
|
28
|
+
const authProvider = new authProviders.TokenCredentialAuthenticationProvider(credential, {
|
|
29
|
+
scopes: ['https://graph.microsoft.com/.default']
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const client = graph.Client.initWithMiddleware({
|
|
33
|
+
authProvider: authProvider
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
ConnectionManager.addConnectionInstance(connection, client)
|
|
37
|
+
|
|
38
|
+
ConnectionManager.logger.info(
|
|
39
|
+
`msgraph-connector connection(${connection.name}:${connection.endpoint}) is connected`
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async disconnect(connection) {
|
|
44
|
+
const client = ConnectionManager.getConnectionInstance(connection)
|
|
45
|
+
// TODO implement how to stop connection
|
|
46
|
+
ConnectionManager.removeConnectionInstance(connection)
|
|
47
|
+
|
|
48
|
+
ConnectionManager.logger.info(`msgraph-connector connection(${connection.name}) is disconnected`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get parameterSpec() {
|
|
52
|
+
/* To get proper settings, refer https://developer.microsoft.com/en-us/graph/quick-start */
|
|
53
|
+
return [
|
|
54
|
+
{
|
|
55
|
+
type: 'string',
|
|
56
|
+
name: 'clientId',
|
|
57
|
+
label: 'client-id'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: 'string',
|
|
61
|
+
name: 'clientSecret',
|
|
62
|
+
label: 'client-secret'
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'string',
|
|
66
|
+
name: 'tenantId',
|
|
67
|
+
label: 'tenant-id'
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: 'string',
|
|
71
|
+
name: 'authTenantId',
|
|
72
|
+
label: 'auth-tenant-id'
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
type: 'string',
|
|
76
|
+
name: 'graphUserScopes',
|
|
77
|
+
label: 'graph-user-scopes'
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get taskPrefixes() {
|
|
83
|
+
return ['msgraph']
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get description() {
|
|
87
|
+
return 'Graph API Connector'
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
ConnectionManager.registerConnector('msgraph-connector', new MsGraphConnector())
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './msgraph-get-users'
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { TaskRegistry } from '@things-factory/integration-base'
|
|
2
|
+
import { ConnectionManager } from '@things-factory/integration-base'
|
|
3
|
+
|
|
4
|
+
async function MsGraphGetUsers(step, context) {
|
|
5
|
+
var { connection: connectionName, params: stepOptions } = step
|
|
6
|
+
var { select, page = 0, limit = 30, orderby } = stepOptions || {}
|
|
7
|
+
var { domain, data, variables } = context
|
|
8
|
+
|
|
9
|
+
var client = ConnectionManager.getConnectionInstanceByName(domain, connectionName)
|
|
10
|
+
|
|
11
|
+
select ||= 'displayName,id,mail'
|
|
12
|
+
orderby ||= 'displayName'
|
|
13
|
+
|
|
14
|
+
const result = await client?.api('/users').select(select.split(',')).top(limit).orderby(orderby).get()
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
data: result
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
MsGraphGetUsers.parameterSpec = [
|
|
22
|
+
{
|
|
23
|
+
type: 'string',
|
|
24
|
+
name: 'select',
|
|
25
|
+
label: 'select'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: 'number',
|
|
29
|
+
name: 'page',
|
|
30
|
+
label: 'page'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: 'number',
|
|
34
|
+
name: 'limit',
|
|
35
|
+
label: 'limit'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: 'string',
|
|
39
|
+
name: 'orderby',
|
|
40
|
+
label: 'orderby'
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
MsGraphGetUsers.help = 'integration/msgraph/task/get-users'
|
|
44
|
+
|
|
45
|
+
TaskRegistry.registerTaskHandler('msgraph-get-users', MsGraphGetUsers)
|
package/server/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './engine'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|