@things-factory/integration-msgraph 8.0.0 → 9.0.0-beta.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-msgraph",
3
- "version": "8.0.0",
3
+ "version": "9.0.0-beta.3",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -25,8 +25,8 @@
25
25
  "dependencies": {
26
26
  "@azure/identity": "^3.1.3",
27
27
  "@microsoft/microsoft-graph-client": "^3.0.5",
28
- "@things-factory/integration-base": "^8.0.0",
28
+ "@things-factory/integration-base": "^9.0.0-beta.3",
29
29
  "cross-fetch": "^3.0.4"
30
30
  },
31
- "gitHead": "07ef27d272dd9a067a9648ac7013748510556a18"
31
+ "gitHead": "1d7e0dd4c88f3c3f3bd311c00e4b1d1542d53634"
32
32
  }
@@ -1 +0,0 @@
1
- import './msgraph-connector'
@@ -1,86 +0,0 @@
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 }
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
- }
76
-
77
- get taskPrefixes() {
78
- return ['msgraph']
79
- }
80
-
81
- get description() {
82
- return 'Graph API Connector'
83
- }
84
- }
85
-
86
- ConnectionManager.registerConnector('msgraph-connector', new MsGraphConnector())
@@ -1,2 +0,0 @@
1
- import './connector'
2
- import './task'
@@ -1,2 +0,0 @@
1
- import './msgraph-get'
2
- import './msgraph-post'
@@ -1,67 +0,0 @@
1
- import { TaskRegistry } from '@things-factory/integration-base'
2
- import { ConnectionManager } from '@things-factory/integration-base'
3
-
4
- async function MsGraphGet(step, context) {
5
- var { connection: connectionName, params: stepOptions } = step
6
- var { path, select, filter, skip = 0, top = 30, orderby } = stepOptions || {}
7
- var { domain, data, variables } = context
8
-
9
- var client = ConnectionManager.getConnectionInstanceByName(domain, connectionName)
10
-
11
- select ||= ''
12
- orderby ||= ''
13
- filter ||= ''
14
-
15
- try {
16
- var result = client?.api(path)
17
- select && (result = result.select(select.split(',')))
18
- filter && (result = result.filter(filter))
19
- skip && (result = result.skip(skip))
20
- top && (result = result.top(top))
21
- orderby && (result = result.orderby(orderby))
22
- result = await result.get()
23
-
24
- return {
25
- data: result
26
- }
27
- } catch (err) {
28
- console.error(err)
29
- throw err
30
- }
31
- }
32
-
33
- MsGraphGet.parameterSpec = [
34
- {
35
- type: 'string',
36
- name: 'path',
37
- label: 'path'
38
- },
39
- {
40
- type: 'string',
41
- name: 'select',
42
- label: 'select'
43
- },
44
- {
45
- type: 'number',
46
- name: 'skip',
47
- label: 'skip'
48
- },
49
- {
50
- type: 'number',
51
- name: 'top',
52
- label: 'top'
53
- },
54
- {
55
- type: 'string',
56
- name: 'orderby',
57
- label: 'orderby'
58
- },
59
- {
60
- type: 'string',
61
- name: 'filter',
62
- label: 'filter'
63
- }
64
- ]
65
- MsGraphGet.help = 'integration/task/msgraph-get'
66
-
67
- TaskRegistry.registerTaskHandler('msgraph-get', MsGraphGet)
@@ -1,34 +0,0 @@
1
- import { TaskRegistry } from '@things-factory/integration-base'
2
- import { ConnectionManager } from '@things-factory/integration-base'
3
- import { access } from '@things-factory/utils'
4
-
5
- async function MsGraphPost(step, context) {
6
- var { connection: connectionName, params: stepOptions } = step
7
- var { path, body } = stepOptions || {}
8
- var { domain, data, variables } = context
9
-
10
- var client = ConnectionManager.getConnectionInstanceByName(domain, connectionName)
11
- body = access(body, data)
12
-
13
- const result = await client?.api(path).post(body)
14
-
15
- return {
16
- data: result
17
- }
18
- }
19
-
20
- MsGraphPost.parameterSpec = [
21
- {
22
- type: 'string',
23
- name: 'path',
24
- label: 'path'
25
- },
26
- {
27
- type: 'string',
28
- name: 'body',
29
- label: 'body'
30
- }
31
- ]
32
- MsGraphPost.help = 'integration/task/msgraph-post'
33
-
34
- TaskRegistry.registerTaskHandler('msgraph-post', MsGraphPost)
package/server/index.ts DELETED
@@ -1 +0,0 @@
1
- import './engine'