@things-factory/integration-base 8.0.40 → 9.0.0-9.0.0-beta.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/dist-server/engine/connector/headless-connector.d.ts +23 -0
  2. package/dist-server/engine/connector/headless-connector.js +357 -0
  3. package/dist-server/engine/connector/headless-connector.js.map +1 -0
  4. package/dist-server/engine/connector/http-connector.js +1 -1
  5. package/dist-server/engine/connector/http-connector.js.map +1 -1
  6. package/dist-server/engine/connector/index.d.ts +1 -0
  7. package/dist-server/engine/connector/index.js +1 -0
  8. package/dist-server/engine/connector/index.js.map +1 -1
  9. package/dist-server/engine/index.d.ts +3 -2
  10. package/dist-server/engine/index.js +3 -2
  11. package/dist-server/engine/index.js.map +1 -1
  12. package/dist-server/engine/resource-pool/headless-pool.d.ts +1 -0
  13. package/dist-server/engine/resource-pool/headless-pool.js +62 -0
  14. package/dist-server/engine/resource-pool/headless-pool.js.map +1 -0
  15. package/dist-server/engine/resource-pool/index.d.ts +1 -0
  16. package/dist-server/engine/resource-pool/index.js +5 -0
  17. package/dist-server/engine/resource-pool/index.js.map +1 -0
  18. package/dist-server/engine/task/headless-post.js +19 -33
  19. package/dist-server/engine/task/headless-post.js.map +1 -1
  20. package/dist-server/engine/task/headless-scrap.js +20 -13
  21. package/dist-server/engine/task/headless-scrap.js.map +1 -1
  22. package/dist-server/index.d.ts +6 -6
  23. package/dist-server/index.js +10 -10
  24. package/dist-server/index.js.map +1 -1
  25. package/dist-server/routes.js +6 -6
  26. package/dist-server/routes.js.map +1 -1
  27. package/dist-server/service/connection/connection-mutation.js +17 -5
  28. package/dist-server/service/connection/connection-mutation.js.map +1 -1
  29. package/dist-server/service/connection/connection-query.js +3 -0
  30. package/dist-server/service/connection/connection-query.js.map +1 -1
  31. package/dist-server/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +12 -11
  33. package/translations/en.json +12 -4
  34. package/translations/ja.json +12 -4
  35. package/translations/ko.json +12 -4
  36. package/translations/ms.json +12 -4
  37. package/translations/zh.json +12 -4
  38. package/server/controllers/index.ts +0 -2
  39. package/server/controllers/publish-data.ts +0 -29
  40. package/server/controllers/scenario-controller.ts +0 -154
  41. package/server/engine/analyzer/analyze-integration.ts +0 -115
  42. package/server/engine/connection-manager.ts +0 -232
  43. package/server/engine/connector/echo-back-connector.ts +0 -51
  44. package/server/engine/connector/echo-back-server.ts +0 -72
  45. package/server/engine/connector/graphql-connector.ts +0 -126
  46. package/server/engine/connector/http-connector.ts +0 -65
  47. package/server/engine/connector/index.ts +0 -12
  48. package/server/engine/connector/mqtt-connector.ts +0 -78
  49. package/server/engine/connector/mssql-connector.ts +0 -152
  50. package/server/engine/connector/mysql-connector.ts +0 -94
  51. package/server/engine/connector/operato-connector.ts +0 -264
  52. package/server/engine/connector/oracle-connector.ts +0 -218
  53. package/server/engine/connector/postgresql-connector.ts +0 -152
  54. package/server/engine/connector/proxy-connector.ts +0 -53
  55. package/server/engine/connector/socket-server.ts +0 -86
  56. package/server/engine/connector/sqlite-connector.ts +0 -69
  57. package/server/engine/edge-client.ts +0 -45
  58. package/server/engine/index.ts +0 -10
  59. package/server/engine/pending-queue.ts +0 -97
  60. package/server/engine/scenario-engine.ts +0 -106
  61. package/server/engine/task/book-up-scenario.ts +0 -73
  62. package/server/engine/task/csv-readline.ts +0 -127
  63. package/server/engine/task/data-accessor.ts +0 -36
  64. package/server/engine/task/data-mapper.ts +0 -47
  65. package/server/engine/task/database-query.ts +0 -56
  66. package/server/engine/task/echo-receive.ts +0 -21
  67. package/server/engine/task/echo-send.ts +0 -32
  68. package/server/engine/task/empty-check.ts +0 -38
  69. package/server/engine/task/end.ts +0 -18
  70. package/server/engine/task/floating-point.ts +0 -71
  71. package/server/engine/task/goto.ts +0 -27
  72. package/server/engine/task/graphql-mutate.ts +0 -79
  73. package/server/engine/task/graphql-query.ts +0 -78
  74. package/server/engine/task/headless-post.ts +0 -147
  75. package/server/engine/task/headless-scrap.ts +0 -80
  76. package/server/engine/task/http-get.ts +0 -117
  77. package/server/engine/task/http-post.ts +0 -148
  78. package/server/engine/task/index.ts +0 -45
  79. package/server/engine/task/jsonata.ts +0 -45
  80. package/server/engine/task/local-graphql-mutate.ts +0 -100
  81. package/server/engine/task/local-graphql-query.ts +0 -100
  82. package/server/engine/task/log.ts +0 -78
  83. package/server/engine/task/mqtt-publish.ts +0 -69
  84. package/server/engine/task/mqtt-subscribe.ts +0 -291
  85. package/server/engine/task/mssql-procedure.ts +0 -128
  86. package/server/engine/task/oracle-procedure.ts +0 -124
  87. package/server/engine/task/pick-pending-scenario.ts +0 -80
  88. package/server/engine/task/publish.ts +0 -40
  89. package/server/engine/task/random.ts +0 -53
  90. package/server/engine/task/reset-pending-queue.ts +0 -17
  91. package/server/engine/task/script.ts +0 -63
  92. package/server/engine/task/set-domain.ts +0 -37
  93. package/server/engine/task/sleep.ts +0 -34
  94. package/server/engine/task/socket-listener.ts +0 -96
  95. package/server/engine/task/state-group-read.ts +0 -69
  96. package/server/engine/task/state-read.ts +0 -56
  97. package/server/engine/task/state-write.ts +0 -65
  98. package/server/engine/task/stop-scenario.ts +0 -44
  99. package/server/engine/task/sub-scenario.ts +0 -57
  100. package/server/engine/task/switch-goto.ts +0 -43
  101. package/server/engine/task/switch-range-goto.ts +0 -53
  102. package/server/engine/task/switch-range-scenario.ts +0 -79
  103. package/server/engine/task/switch-range-set.ts +0 -48
  104. package/server/engine/task/switch-scenario.ts +0 -67
  105. package/server/engine/task/switch-set.ts +0 -37
  106. package/server/engine/task/throw.ts +0 -27
  107. package/server/engine/task/utils/headless-pool-for-scenario.ts +0 -71
  108. package/server/engine/task/utils/substitute.ts +0 -44
  109. package/server/engine/task/variables.ts +0 -17
  110. package/server/engine/task-registry.ts +0 -23
  111. package/server/engine/types.ts +0 -114
  112. package/server/index.ts +0 -20
  113. package/server/migrations/index.ts +0 -9
  114. package/server/restful/index.ts +0 -1
  115. package/server/restful/unstable/index.ts +0 -7
  116. package/server/restful/unstable/run-scenario.ts +0 -51
  117. package/server/restful/unstable/scenario-instance.ts +0 -52
  118. package/server/restful/unstable/scenario-instances.ts +0 -80
  119. package/server/restful/unstable/scenario.ts +0 -41
  120. package/server/restful/unstable/scenarios.ts +0 -69
  121. package/server/restful/unstable/start-scenario.ts +0 -33
  122. package/server/restful/unstable/stop-scenario.ts +0 -30
  123. package/server/routers/scenario-schedule-callback-router.ts +0 -69
  124. package/server/routers/scenario-view-router.ts +0 -46
  125. package/server/routes.ts +0 -35
  126. package/server/service/analysis/analysis-query.ts +0 -13
  127. package/server/service/analysis/index.ts +0 -3
  128. package/server/service/connection/connection-mutation.ts +0 -190
  129. package/server/service/connection/connection-query.ts +0 -87
  130. package/server/service/connection/connection-subscription.ts +0 -104
  131. package/server/service/connection/connection-type.ts +0 -305
  132. package/server/service/connection/index.ts +0 -7
  133. package/server/service/connector/connector-query.ts +0 -62
  134. package/server/service/connector/connector-type.ts +0 -29
  135. package/server/service/connector/index.ts +0 -4
  136. package/server/service/index.ts +0 -52
  137. package/server/service/payload-log/index.ts +0 -7
  138. package/server/service/payload-log/payload-log-mutation.ts +0 -151
  139. package/server/service/payload-log/payload-log-query.ts +0 -49
  140. package/server/service/payload-log/payload-log-type.ts +0 -36
  141. package/server/service/payload-log/payload-log.ts +0 -100
  142. package/server/service/property-spec.ts +0 -24
  143. package/server/service/scenario/index.ts +0 -6
  144. package/server/service/scenario/scenario-mutation.ts +0 -396
  145. package/server/service/scenario/scenario-query.ts +0 -109
  146. package/server/service/scenario/scenario-type.ts +0 -78
  147. package/server/service/scenario/scenario.ts +0 -124
  148. package/server/service/scenario-flow/scenario-flow.ts +0 -17
  149. package/server/service/scenario-instance/index.ts +0 -6
  150. package/server/service/scenario-instance/scenario-instance-mutation.ts +0 -44
  151. package/server/service/scenario-instance/scenario-instance-query.ts +0 -42
  152. package/server/service/scenario-instance/scenario-instance-subscription.ts +0 -118
  153. package/server/service/scenario-instance/scenario-instance-type.ts +0 -557
  154. package/server/service/scenario-queue/index.ts +0 -4
  155. package/server/service/scenario-queue/scenario-queue-subscription.ts +0 -55
  156. package/server/service/scenario-queue/scenario-queue-type.ts +0 -27
  157. package/server/service/state-register/data-resolver.ts +0 -56
  158. package/server/service/state-register/index.ts +0 -8
  159. package/server/service/state-register/state-register-mutation.ts +0 -166
  160. package/server/service/state-register/state-register-query.ts +0 -80
  161. package/server/service/state-register/state-register-type.ts +0 -80
  162. package/server/service/state-register/state-register.ts +0 -113
  163. package/server/service/step/index.ts +0 -6
  164. package/server/service/step/step-mutation.ts +0 -52
  165. package/server/service/step/step-query.ts +0 -55
  166. package/server/service/step/step-type.ts +0 -238
  167. package/server/service/task-type/index.ts +0 -4
  168. package/server/service/task-type/task-type-query.ts +0 -95
  169. package/server/service/task-type/task-type-type.ts +0 -29
@@ -6,17 +6,16 @@ const url_1 = require("url");
6
6
  const utils_1 = require("@things-factory/utils");
7
7
  const task_registry_1 = require("../task-registry");
8
8
  const connection_manager_1 = require("../connection-manager");
9
- const headless_pool_for_scenario_1 = require("./utils/headless-pool-for-scenario");
10
9
  async function HeadlessPost(step, { logger, data, domain }) {
11
- var { connection: connectionName, params: stepOptions } = step;
12
- var { headers: requestHeaders, contentType, path, accessor } = stepOptions || {};
13
- var connection = connection_manager_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
10
+ const { connection: connectionName, params: stepOptions } = step;
11
+ const { headers: requestHeaders, contentType, path, accessor } = stepOptions || {};
12
+ const connection = connection_manager_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
14
13
  if (!connection) {
15
- throw new Error(`connection '${connectionName}' is not established.`);
14
+ throw new Error(`Connection '${connectionName}' is not established.`);
16
15
  }
17
- var { endpoint, params: connectionParams, authHeaders = {} } = connection;
18
- var headers = Object.assign(Object.assign({}, authHeaders), requestHeaders);
19
- var body = (0, utils_1.access)(accessor, data);
16
+ const { endpoint, params: connectionParams, acquireSessionPage, releasePage } = connection;
17
+ const headers = Object.assign({}, requestHeaders);
18
+ let body = (0, utils_1.access)(accessor, data);
20
19
  if (contentType && body) {
21
20
  headers['content-type'] = contentType;
22
21
  switch (contentType) {
@@ -31,24 +30,23 @@ async function HeadlessPost(step, { logger, data, domain }) {
31
30
  for (const prop in body) {
32
31
  searchParams.set(prop, body[prop]);
33
32
  }
34
- body = searchParams;
33
+ body = searchParams.toString();
35
34
  break;
36
35
  }
37
36
  }
38
- var options = {
37
+ const options = {
39
38
  method: 'POST',
40
39
  headers,
41
40
  body
42
41
  };
43
- var { rejectUnauthorized } = connectionParams;
42
+ const { rejectUnauthorized } = connectionParams;
44
43
  if (!rejectUnauthorized) {
45
44
  const httpsAgent = new https_1.default.Agent({
46
45
  rejectUnauthorized
47
46
  });
48
47
  options.agent = httpsAgent;
49
48
  }
50
- const browser = (await (0, headless_pool_for_scenario_1.getHeadlessPool)().acquire());
51
- const page = await browser.newPage();
49
+ const page = await acquireSessionPage();
52
50
  try {
53
51
  page.on('console', async (msg) => {
54
52
  console.log(`[browser ${msg.type()}] ${msg.text()}`);
@@ -70,12 +68,12 @@ async function HeadlessPost(step, { logger, data, domain }) {
70
68
  data: response
71
69
  };
72
70
  }
73
- catch (e) {
74
- console.error(e);
71
+ catch (error) {
72
+ logger.error('Error in HeadlessPost:', error);
73
+ throw error;
75
74
  }
76
75
  finally {
77
- page.close();
78
- (0, headless_pool_for_scenario_1.getHeadlessPool)().release(browser);
76
+ await releasePage(page);
79
77
  }
80
78
  }
81
79
  HeadlessPost.parameterSpec = [
@@ -95,22 +93,10 @@ HeadlessPost.parameterSpec = [
95
93
  label: 'content-type',
96
94
  property: {
97
95
  options: [
98
- {
99
- display: '',
100
- value: ''
101
- },
102
- {
103
- display: 'application/json',
104
- value: 'application/json'
105
- },
106
- {
107
- display: 'text/plain',
108
- value: 'text/plain'
109
- },
110
- {
111
- display: 'application/x-www-form-urlencoded',
112
- value: 'application/x-www-form-urlencoded'
113
- }
96
+ { display: '', value: '' },
97
+ { display: 'application/json', value: 'application/json' },
98
+ { display: 'text/plain', value: 'text/plain' },
99
+ { display: 'application/x-www-form-urlencoded', value: 'application/x-www-form-urlencoded' }
114
100
  ]
115
101
  }
116
102
  },
@@ -1 +1 @@
1
- {"version":3,"file":"headless-post.js","sourceRoot":"","sources":["../../../server/engine/task/headless-post.ts"],"names":[],"mappings":";;;AAAA,0DAAyB;AACzB,6BAAyB;AAEzB,iDAA8C;AAC9C,oDAA+C;AAC/C,8DAAyD;AAEzD,mFAAoE;AAKpE,KAAK,UAAU,YAAY,CAAC,IAAe,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAW;IAC5E,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;IAC9D,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,WAAW,IAAI,EAAE,CAAA;IAEhF,IAAI,UAAU,GAAG,sCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAEtF,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,eAAe,cAAc,uBAAuB,CAAC,CAAA;IACvE,CAAC;IAED,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,UAAU,CAAA;IAEzE,IAAI,OAAO,mCACN,WAAW,GACX,cAAc,CAClB,CAAA;IAED,IAAI,IAAI,GAAG,IAAA,cAAM,EAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IACjC,IAAI,WAAW,IAAI,IAAI,EAAE,CAAC;QACxB,OAAO,CAAC,cAAc,CAAC,GAAG,WAAW,CAAA;QACrC,QAAQ,WAAW,EAAE,CAAC;YACpB,KAAK,YAAY;gBACf,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;gBAC3B,MAAK;YACP,KAAK,kBAAkB;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BACD;oBACE,OAAO,EAAE,kBAAkB;oBAC3B,KAAK,EAAE,kBAAkB;iBAC1B;gBACD;oBACE,OAAO,EAAE,YAAY;oBACrB,KAAK,EAAE,YAAY;iBACpB;gBACD;oBACE,OAAO,EAAE,mCAAmC;oBAC5C,KAAK,EAAE,mCAAmC;iBAC3C;aACF;SACF;KACF;IACD;QACE,IAAI,EAAE,qBAAqB;QAC3B,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;KAClB;CACF,CAAA;AAED,4BAAY,CAAC,mBAAmB,CAAC,eAAe,EAAE,YAAY,CAAC,CAAA","sourcesContent":["import https from 'https'\nimport { URL } from 'url'\n\nimport { access } from '@things-factory/utils'\nimport { TaskRegistry } from '../task-registry'\nimport { ConnectionManager } from '../connection-manager'\n\nimport { getHeadlessPool } from './utils/headless-pool-for-scenario'\n\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\nasync function HeadlessPost(step: InputStep, { logger, data, domain }: Context) {\n var { connection: connectionName, params: stepOptions } = step\n var { headers: requestHeaders, contentType, path, accessor } = stepOptions || {}\n\n var connection = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n if (!connection) {\n throw new Error(`connection '${connectionName}' is not established.`)\n }\n\n var { endpoint, params: connectionParams, authHeaders = {} } = connection\n\n var headers = {\n ...authHeaders,\n ...requestHeaders\n }\n\n var body = access(accessor, data)\n if (contentType && body) {\n headers['content-type'] = contentType\n switch (contentType) {\n case 'text/plain':\n body = JSON.stringify(body)\n break\n case 'application/json':\n body = JSON.stringify(body)\n break\n case 'application/x-www-form-urlencoded':\n const searchParams = new URLSearchParams()\n for (const prop in body) {\n searchParams.set(prop, body[prop])\n }\n body = searchParams\n break\n }\n }\n\n var options: any = {\n method: 'POST',\n headers,\n body\n }\n\n var { rejectUnauthorized } = connectionParams\n\n if (!rejectUnauthorized) {\n const httpsAgent = new https.Agent({\n rejectUnauthorized\n })\n options.agent = httpsAgent\n }\n\n const browser = (await getHeadlessPool().acquire()) as any\n const page = await browser.newPage()\n\n try {\n page.on('console', async msg => {\n console.log(`[browser ${msg.type()}] ${msg.text()}`)\n })\n\n page.on('requestfailed', request => {\n console.log('Request failed:', request.url())\n })\n\n await page.goto(endpoint, { waitUntil: 'networkidle2' })\n\n const response = await page.evaluate(\n async (urlString, options) => {\n const response = await fetch(urlString, options)\n\n if (response.ok && response.headers.get('content-type').includes('application/json')) {\n return await response.json()\n } else {\n return await response.text()\n }\n },\n new URL(path, endpoint),\n options\n )\n\n return {\n data: response\n }\n } catch (e) {\n console.error(e)\n } finally {\n page.close()\n getHeadlessPool().release(browser)\n }\n}\n\nHeadlessPost.parameterSpec = [\n {\n type: 'string',\n name: 'path',\n label: 'path'\n },\n {\n type: 'http-headers',\n name: 'headers',\n label: 'headers'\n },\n {\n type: 'select',\n name: 'contentType',\n label: 'content-type',\n property: {\n options: [\n {\n display: '',\n value: ''\n },\n {\n display: 'application/json',\n value: 'application/json'\n },\n {\n display: 'text/plain',\n value: 'text/plain'\n },\n {\n display: 'application/x-www-form-urlencoded',\n value: 'application/x-www-form-urlencoded'\n }\n ]\n }\n },\n {\n type: 'scenario-step-input',\n name: 'accessor',\n label: 'accessor'\n }\n]\n\nTaskRegistry.registerTaskHandler('headless-post', HeadlessPost)\n"]}
1
+ {"version":3,"file":"headless-post.js","sourceRoot":"","sources":["../../../server/engine/task/headless-post.ts"],"names":[],"mappings":";;;AAAA,0DAAyB;AACzB,6BAAyB;AAEzB,iDAA8C;AAC9C,oDAA+C;AAC/C,8DAAyD;AAEzD,KAAK,UAAU,YAAY,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE;IACxD,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;IAChE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,WAAW,IAAI,EAAE,CAAA;IAEl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AAC;QACf,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAA;QAC7C,MAAM,KAAK,CAAA;IACb,CAAC;YAAS,CAAC;QACT,MAAM,WAAW,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;AACH,CAAC;AAED,YAAY,CAAC,aAAa,GAAG;IAC3B;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,MAAM;KACd;IACD;QACE,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,cAAc;QACrB,QAAQ,EAAE;YACR,OAAO,EAAE;gBACP,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;gBAC1B,EAAE,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,kBAAkB,EAAE;gBAC1D,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE;gBAC9C,EAAE,OAAO,EAAE,mCAAmC,EAAE,KAAK,EAAE,mCAAmC,EAAE;aAC7F;SACF;KACF;IACD;QACE,IAAI,EAAE,qBAAqB;QAC3B,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;KAClB;CACF,CAAA;AAED,4BAAY,CAAC,mBAAmB,CAAC,eAAe,EAAE,YAAY,CAAC,CAAA","sourcesContent":["import https from 'https'\nimport { URL } from 'url'\n\nimport { access } from '@things-factory/utils'\nimport { TaskRegistry } from '../task-registry'\nimport { ConnectionManager } from '../connection-manager'\n\nasync function HeadlessPost(step, { logger, data, domain }) {\n const { connection: connectionName, params: stepOptions } = step\n const { headers: requestHeaders, contentType, path, accessor } = stepOptions || {}\n\n const connection = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n if (!connection) {\n throw new Error(`Connection '${connectionName}' is not established.`)\n }\n\n const { endpoint, params: connectionParams, acquireSessionPage, releasePage } = connection\n\n const headers = {\n ...requestHeaders\n }\n\n let body = access(accessor, data)\n if (contentType && body) {\n headers['content-type'] = contentType\n switch (contentType) {\n case 'text/plain':\n body = JSON.stringify(body)\n break\n case 'application/json':\n body = JSON.stringify(body)\n break\n case 'application/x-www-form-urlencoded':\n const searchParams = new URLSearchParams()\n for (const prop in body) {\n searchParams.set(prop, body[prop])\n }\n body = searchParams.toString()\n break\n }\n }\n\n const options = {\n method: 'POST',\n headers,\n body\n } as any\n\n const { rejectUnauthorized } = connectionParams\n\n if (!rejectUnauthorized) {\n const httpsAgent = new https.Agent({\n rejectUnauthorized\n })\n options.agent = httpsAgent\n }\n\n const page = await acquireSessionPage()\n\n try {\n page.on('console', async msg => {\n console.log(`[browser ${msg.type()}] ${msg.text()}`)\n })\n\n page.on('requestfailed', request => {\n console.log('Request failed:', request.url())\n })\n\n await page.goto(endpoint, { waitUntil: 'networkidle2' })\n\n const response = await page.evaluate(\n async (urlString, options) => {\n const response = await fetch(urlString, options)\n\n if (response.ok && response.headers.get('content-type').includes('application/json')) {\n return await response.json()\n } else {\n return await response.text()\n }\n },\n new URL(path, endpoint),\n options\n )\n\n return {\n data: response\n }\n } catch (error) {\n logger.error('Error in HeadlessPost:', error)\n throw error\n } finally {\n await releasePage(page)\n }\n}\n\nHeadlessPost.parameterSpec = [\n {\n type: 'string',\n name: 'path',\n label: 'path'\n },\n {\n type: 'http-headers',\n name: 'headers',\n label: 'headers'\n },\n {\n type: 'select',\n name: 'contentType',\n label: 'content-type',\n property: {\n options: [\n { display: '', value: '' },\n { display: 'application/json', value: 'application/json' },\n { display: 'text/plain', value: 'text/plain' },\n { display: 'application/x-www-form-urlencoded', value: 'application/x-www-form-urlencoded' }\n ]\n }\n },\n {\n type: 'scenario-step-input',\n name: 'accessor',\n label: 'accessor'\n }\n]\n\nTaskRegistry.registerTaskHandler('headless-post', HeadlessPost)\n"]}
@@ -3,24 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const url_1 = require("url");
4
4
  const task_registry_1 = require("../task-registry");
5
5
  const connection_manager_1 = require("../connection-manager");
6
- const headless_pool_for_scenario_1 = require("./utils/headless-pool-for-scenario");
7
6
  async function HeadlessScrap(step, { logger, data, domain }) {
8
- var { connection: connectionName, params: stepOptions } = step;
9
- var { headers: requestHeaders, path, selectors = [] } = stepOptions || {};
10
- var connection = connection_manager_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
7
+ const { connection: connectionName, params: stepOptions } = step;
8
+ const { headers: requestHeaders, path, selectors = [] } = stepOptions || {};
9
+ const connection = connection_manager_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
11
10
  if (!connection) {
12
- throw new Error(`connection '${connectionName}' is not established.`);
11
+ throw new Error(`Connection '${connectionName}' is not established.`);
13
12
  }
14
- var { endpoint, params: connectionParams, authHeaders = {} } = connection;
15
- var headers = Object.assign(Object.assign({}, authHeaders), requestHeaders);
16
- const browser = (await (0, headless_pool_for_scenario_1.getHeadlessPool)().acquire());
17
- const page = await browser.newPage();
13
+ const { endpoint, params: connectionParams, acquireSessionPage, releasePage } = connection;
14
+ const headers = Object.assign({}, requestHeaders);
15
+ const page = await acquireSessionPage();
18
16
  try {
19
17
  page.on('console', async (msg) => {
20
18
  console.log(`[browser ${msg.type()}] ${msg.text()}`);
21
19
  });
22
20
  page.on('requestfailed', request => {
23
- console.log('Request failed:', request.url());
21
+ var _a;
22
+ console.log('Request failed:');
23
+ console.log(`- URL: ${request.url()}`);
24
+ console.log(`- Method: ${request.method()}`);
25
+ console.log(`- Failure Text: ${(_a = request.failure()) === null || _a === void 0 ? void 0 : _a.errorText}`);
26
+ console.log(`- Headers:`, request.headers());
27
+ // POST 데이터 (필요한 경우)
28
+ if (request.postData()) {
29
+ console.log(`- Post Data: ${request.postData()}`);
30
+ }
24
31
  });
25
32
  await page.setExtraHTTPHeaders(headers);
26
33
  await page.goto(new url_1.URL(path, endpoint), { waitUntil: 'networkidle2' });
@@ -36,11 +43,11 @@ async function HeadlessScrap(step, { logger, data, domain }) {
36
43
  };
37
44
  }
38
45
  catch (e) {
39
- console.error(e);
46
+ logger.error('Error in HeadlessScrap:', e);
47
+ throw e;
40
48
  }
41
49
  finally {
42
- page.close();
43
- (0, headless_pool_for_scenario_1.getHeadlessPool)().release(browser);
50
+ await releasePage(page);
44
51
  }
45
52
  }
46
53
  HeadlessScrap.parameterSpec = [
@@ -1 +1 @@
1
- {"version":3,"file":"headless-scrap.js","sourceRoot":"","sources":["../../../server/engine/task/headless-scrap.ts"],"names":[],"mappings":";;AAAA,6BAAyB;AAEzB,oDAA+C;AAC/C,8DAAyD;AAEzD,mFAAoE;AAIpE,KAAK,UAAU,aAAa,CAAC,IAAe,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAW;IAC7E,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;IAC9D,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,WAAW,IAAI,EAAE,CAAA;IAEzE,IAAI,UAAU,GAAG,sCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAEtF,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,eAAe,cAAc,uBAAuB,CAAC,CAAA;IACvE,CAAC;IAED,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,UAAU,CAAA;IAEzE,IAAI,OAAO,mCACN,WAAW,GACX,cAAc,CAClB,CAAA;IAED,MAAM,OAAO,GAAG,CAAC,MAAM,IAAA,4CAAe,GAAE,CAAC,OAAO,EAAE,CAAQ,CAAA;IAC1D,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,CAAA;IAEpC,IAAI,CAAC;QACH,IAAI,CAAC,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AAG;IAC5B;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,MAAM;KACd;IACD;QACE,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB;IACD;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,WAAW;KACnB;CACF,CAAA;AAED,4BAAY,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAA","sourcesContent":["import { URL } from 'url'\n\nimport { TaskRegistry } from '../task-registry'\nimport { ConnectionManager } from '../connection-manager'\n\nimport { getHeadlessPool } from './utils/headless-pool-for-scenario'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\nasync function HeadlessScrap(step: InputStep, { logger, data, domain }: Context) {\n var { connection: connectionName, params: stepOptions } = step\n var { headers: requestHeaders, path, selectors = [] } = stepOptions || {}\n\n var connection = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n if (!connection) {\n throw new Error(`connection '${connectionName}' is not established.`)\n }\n\n var { endpoint, params: connectionParams, authHeaders = {} } = connection\n\n var headers = {\n ...authHeaders,\n ...requestHeaders\n }\n\n const browser = (await getHeadlessPool().acquire()) as any\n const page = await browser.newPage()\n\n try {\n page.on('console', async msg => {\n console.log(`[browser ${msg.type()}] ${msg.text()}`)\n })\n\n page.on('requestfailed', request => {\n console.log('Request failed:', request.url())\n })\n\n await page.setExtraHTTPHeaders(headers)\n await page.goto(new URL(path, endpoint), { waitUntil: 'networkidle2' })\n\n const result = {}\n\n for (const selector of selectors) {\n const { text, value } = selector\n result[text] = await page.$$eval(value, elements => {\n return elements.map(element => element.textContent.trim())\n })\n }\n\n return {\n data: result\n }\n } catch (e) {\n console.error(e)\n } finally {\n page.close()\n getHeadlessPool().release(browser)\n }\n}\n\nHeadlessScrap.parameterSpec = [\n {\n type: 'string',\n name: 'path',\n label: 'path'\n },\n {\n type: 'http-headers',\n name: 'headers',\n label: 'headers'\n },\n {\n type: 'options',\n name: 'selectors',\n label: 'selectors'\n }\n]\n\nTaskRegistry.registerTaskHandler('headless-scrap', HeadlessScrap)\n"]}
1
+ {"version":3,"file":"headless-scrap.js","sourceRoot":"","sources":["../../../server/engine/task/headless-scrap.ts"],"names":[],"mappings":";;AAAA,6BAAyB;AAEzB,oDAA+C;AAC/C,8DAAyD;AAEzD,KAAK,UAAU,aAAa,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE;IACzD,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;IAChE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,WAAW,IAAI,EAAE,CAAA;IAE3E,MAAM,UAAU,GAAG,sCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAExF,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,eAAe,cAAc,uBAAuB,CAAC,CAAA;IACvE,CAAC;IAED,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,WAAW,EAAE,GAAG,UAAU,CAAA;IAE1F,MAAM,OAAO,qBACR,cAAc,CAClB,CAAA;IAED,MAAM,IAAI,GAAG,MAAM,kBAAkB,EAAE,CAAA;IAEvC,IAAI,CAAC;QACH,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,EAAC,GAAG,EAAC,EAAE;YAC7B,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QACtD,CAAC,CAAC,CAAA;QAEF,IAAI,CAAC,EAAE,CAAC,eAAe,EAAE,OAAO,CAAC,EAAE;;YACjC,OAAO,CAAC,GAAG,CAAC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AC,yBAAyB,EAAE,CAAC,CAAC,CAAA;QAC1C,MAAM,CAAC,CAAA;IACT,CAAC;YAAS,CAAC;QACT,MAAM,WAAW,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;AACH,CAAC;AAED,aAAa,CAAC,aAAa,GAAG;IAC5B;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,MAAM;KACd;IACD;QACE,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB;IACD;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,WAAW;KACnB;CACF,CAAA;AAED,4BAAY,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAA","sourcesContent":["import { URL } from 'url'\n\nimport { TaskRegistry } from '../task-registry'\nimport { ConnectionManager } from '../connection-manager'\n\nasync function HeadlessScrap(step, { logger, data, domain }) {\n const { connection: connectionName, params: stepOptions } = step\n const { headers: requestHeaders, path, selectors = [] } = stepOptions || {}\n\n const connection = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n if (!connection) {\n throw new Error(`Connection '${connectionName}' is not established.`)\n }\n\n const { endpoint, params: connectionParams, acquireSessionPage, releasePage } = connection\n\n const headers = {\n ...requestHeaders\n }\n\n const page = await acquireSessionPage()\n\n try {\n page.on('console', async msg => {\n console.log(`[browser ${msg.type()}] ${msg.text()}`)\n })\n\n page.on('requestfailed', request => {\n console.log('Request failed:')\n console.log(`- URL: ${request.url()}`)\n console.log(`- Method: ${request.method()}`)\n console.log(`- Failure Text: ${request.failure()?.errorText}`)\n console.log(`- Headers:`, request.headers())\n\n // POST 데이터 (필요한 경우)\n if (request.postData()) {\n console.log(`- Post Data: ${request.postData()}`)\n }\n })\n\n await page.setExtraHTTPHeaders(headers)\n await page.goto(new URL(path, endpoint), { waitUntil: 'networkidle2' })\n\n const result = {}\n\n for (const selector of selectors) {\n const { text, value } = selector\n result[text] = await page.$$eval(value, elements => {\n return elements.map(element => element.textContent.trim())\n })\n }\n\n return {\n data: result\n }\n } catch (e) {\n logger.error('Error in HeadlessScrap:', e)\n throw e\n } finally {\n await releasePage(page)\n }\n}\n\nHeadlessScrap.parameterSpec = [\n {\n type: 'string',\n name: 'path',\n label: 'path'\n },\n {\n type: 'http-headers',\n name: 'headers',\n label: 'headers'\n },\n {\n type: 'options',\n name: 'selectors',\n label: 'selectors'\n }\n]\n\nTaskRegistry.registerTaskHandler('headless-scrap', HeadlessScrap)\n"]}
@@ -1,6 +1,6 @@
1
- export * from './migrations';
2
- export * from './engine';
3
- export * from './controllers';
4
- export * from './service';
5
- import './routes';
6
- import './restful';
1
+ export * from './migrations/index.js';
2
+ export * from './engine/index.js';
3
+ export * from './controllers/index.js';
4
+ export * from './service/index.js';
5
+ import './routes.js';
6
+ import './restful/index.js';
@@ -1,21 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./migrations"), exports);
5
- tslib_1.__exportStar(require("./engine"), exports);
6
- tslib_1.__exportStar(require("./controllers"), exports);
7
- tslib_1.__exportStar(require("./service"), exports);
8
- require("./routes");
9
- require("./restful"); /* APIs */
10
- const engine_1 = require("./engine");
4
+ tslib_1.__exportStar(require("./migrations/index.js"), exports);
5
+ tslib_1.__exportStar(require("./engine/index.js"), exports);
6
+ tslib_1.__exportStar(require("./controllers/index.js"), exports);
7
+ tslib_1.__exportStar(require("./service/index.js"), exports);
8
+ require("./routes.js");
9
+ require("./restful/index.js"); /* APIs */
10
+ const index_js_1 = require("./engine/index.js");
11
11
  process.on('bootstrap-module-start', async ({ app, config, client }) => {
12
12
  try {
13
- await engine_1.ConnectionManager.ready();
14
- await engine_1.ScenarioEngine.loadAll();
13
+ await index_js_1.ConnectionManager.ready();
14
+ await index_js_1.ScenarioEngine.loadAll();
15
15
  console.log('Scenario Engine has just started.');
16
16
  }
17
17
  catch (ex) {
18
- engine_1.ConnectionManager.logger.error('Just has failed to start Scenario Engine.', ex);
18
+ index_js_1.ConnectionManager.logger.error('Just has failed to start Scenario Engine.', ex);
19
19
  }
20
20
  });
21
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,uDAA4B;AAC5B,mDAAwB;AACxB,wDAA6B;AAC7B,oDAAyB;AAEzB,oBAAiB;AACjB,qBAAkB,CAAC,UAAU;AAE7B,qCAA4D;AAE5D,OAAO,CAAC,EAAE,CAAC,wBAA+B,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAO,EAAE,EAAE;IACjF,IAAI,CAAC;QACH,MAAM,0BAAiB,CAAC,KAAK,EAAE,CAAA;QAC/B,MAAM,uBAAc,CAAC,OAAO,EAAE,CAAA;QAE9B,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAA;IAClD,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,0BAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,2CAA2C,EAAE,EAAE,CAAC,CAAA;IACjF,CAAC;AACH,CAAC,CAAC,CAAA","sourcesContent":["export * from './migrations'\nexport * from './engine'\nexport * from './controllers'\nexport * from './service'\n\nimport './routes'\nimport './restful' /* APIs */\n\nimport { ConnectionManager, ScenarioEngine } from './engine'\n\nprocess.on('bootstrap-module-start' as any, async ({ app, config, client }: any) => {\n try {\n await ConnectionManager.ready()\n await ScenarioEngine.loadAll()\n\n console.log('Scenario Engine has just started.')\n } catch (ex) {\n ConnectionManager.logger.error('Just has failed to start Scenario Engine.', ex)\n }\n})\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,gEAAqC;AACrC,4DAAiC;AACjC,iEAAsC;AACtC,6DAAkC;AAElC,uBAAoB;AACpB,8BAA2B,CAAC,UAAU;AAEtC,gDAAqE;AAErE,OAAO,CAAC,EAAE,CAAC,wBAA+B,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAO,EAAE,EAAE;IACjF,IAAI,CAAC;QACH,MAAM,4BAAiB,CAAC,KAAK,EAAE,CAAA;QAC/B,MAAM,yBAAc,CAAC,OAAO,EAAE,CAAA;QAE9B,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAA;IAClD,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,4BAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,2CAA2C,EAAE,EAAE,CAAC,CAAA;IACjF,CAAC;AACH,CAAC,CAAC,CAAA","sourcesContent":["export * from './migrations/index.js'\nexport * from './engine/index.js'\nexport * from './controllers/index.js'\nexport * from './service/index.js'\n\nimport './routes.js'\nimport './restful/index.js' /* APIs */\n\nimport { ConnectionManager, ScenarioEngine } from './engine/index.js'\n\nprocess.on('bootstrap-module-start' as any, async ({ app, config, client }: any) => {\n try {\n await ConnectionManager.ready()\n await ScenarioEngine.loadAll()\n\n console.log('Scenario Engine has just started.')\n } catch (ex) {\n ConnectionManager.logger.error('Just has failed to start Scenario Engine.', ex)\n }\n})\n"]}
@@ -2,23 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const env_1 = require("@things-factory/env");
4
4
  const shell_1 = require("@things-factory/shell");
5
- const scenario_view_router_1 = require("./routers/scenario-view-router");
6
- const scenario_schedule_callback_router_1 = require("./routers/scenario-schedule-callback-router");
5
+ const scenario_view_router_js_1 = require("./routers/scenario-view-router.js");
6
+ const scenario_schedule_callback_router_js_1 = require("./routers/scenario-schedule-callback-router.js");
7
7
  const isPathBaseDomain = !env_1.config.get('subdomain');
8
8
  process.on('bootstrap-module-domain-public-route', (app, domainPrivateRouter) => {
9
9
  if (isPathBaseDomain) {
10
- domainPrivateRouter.use(`/${(0, shell_1.getRoutePrefixForDomainType)()}/:domain`, scenario_schedule_callback_router_1.scenarioScheduleCallbackRouter.routes(), scenario_schedule_callback_router_1.scenarioScheduleCallbackRouter.allowedMethods());
10
+ domainPrivateRouter.use(`/${(0, shell_1.getRoutePrefixForDomainType)()}/:domain`, scenario_schedule_callback_router_js_1.scenarioScheduleCallbackRouter.routes(), scenario_schedule_callback_router_js_1.scenarioScheduleCallbackRouter.allowedMethods());
11
11
  }
12
12
  else {
13
- domainPrivateRouter.use('', scenario_schedule_callback_router_1.scenarioScheduleCallbackRouter.routes(), scenario_schedule_callback_router_1.scenarioScheduleCallbackRouter.allowedMethods());
13
+ domainPrivateRouter.use('', scenario_schedule_callback_router_js_1.scenarioScheduleCallbackRouter.routes(), scenario_schedule_callback_router_js_1.scenarioScheduleCallbackRouter.allowedMethods());
14
14
  }
15
15
  });
16
16
  process.on('bootstrap-module-domain-private-route', (app, domainPrivateRouter) => {
17
17
  if (isPathBaseDomain) {
18
- domainPrivateRouter.use(`/${(0, shell_1.getRoutePrefixForDomainType)()}/:domain`, scenario_view_router_1.scenarioViewRouter.routes(), scenario_view_router_1.scenarioViewRouter.allowedMethods());
18
+ domainPrivateRouter.use(`/${(0, shell_1.getRoutePrefixForDomainType)()}/:domain`, scenario_view_router_js_1.scenarioViewRouter.routes(), scenario_view_router_js_1.scenarioViewRouter.allowedMethods());
19
19
  }
20
20
  else {
21
- domainPrivateRouter.use('', scenario_view_router_1.scenarioViewRouter.routes(), scenario_view_router_1.scenarioViewRouter.allowedMethods());
21
+ domainPrivateRouter.use('', scenario_view_router_js_1.scenarioViewRouter.routes(), scenario_view_router_js_1.scenarioViewRouter.allowedMethods());
22
22
  }
23
23
  });
24
24
  //# sourceMappingURL=routes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;AAAA,6CAA4C;AAC5C,iDAAmE;AAEnE,yEAAmE;AACnE,mGAA4F;AAE5F,MAAM,gBAAgB,GAAG,CAAC,YAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;AAEjD,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,mBAAmB,EAAE,EAAE;IACrF,IAAI,gBAAgB,EAAE,CAAC;QACrB,mBAAmB,CAAC,GAAG,CACrB,IAAI,IAAA,mCAA2B,GAAE,UAAU,EAC3C,kEAA8B,CAAC,MAAM,EAAE,EACvC,kEAA8B,CAAC,cAAc,EAAE,CAChD,CAAA;IACH,CAAC;SAAM,CAAC;QACN,mBAAmB,CAAC,GAAG,CACrB,EAAE,EACF,kEAA8B,CAAC,MAAM,EAAE,EACvC,kEAA8B,CAAC,cAAc,EAAE,CAChD,CAAA;IACH,CAAC;AACH,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,uCAA8C,EAAE,CAAC,GAAG,EAAE,mBAAmB,EAAE,EAAE;IACtF,IAAI,gBAAgB,EAAE,CAAC;QACrB,mBAAmB,CAAC,GAAG,CACrB,IAAI,IAAA,mCAA2B,GAAE,UAAU,EAC3C,yCAAkB,CAAC,MAAM,EAAE,EAC3B,yCAAkB,CAAC,cAAc,EAAE,CACpC,CAAA;IACH,CAAC;SAAM,CAAC;QACN,mBAAmB,CAAC,GAAG,CAAC,EAAE,EAAE,yCAAkB,CAAC,MAAM,EAAE,EAAE,yCAAkB,CAAC,cAAc,EAAE,CAAC,CAAA;IAC/F,CAAC;AACH,CAAC,CAAC,CAAA","sourcesContent":["import { config } from '@things-factory/env'\nimport { getRoutePrefixForDomainType } from '@things-factory/shell'\n\nimport { scenarioViewRouter } from './routers/scenario-view-router'\nimport { scenarioScheduleCallbackRouter } from './routers/scenario-schedule-callback-router'\n\nconst isPathBaseDomain = !config.get('subdomain')\n\nprocess.on('bootstrap-module-domain-public-route' as any, (app, domainPrivateRouter) => {\n if (isPathBaseDomain) {\n domainPrivateRouter.use(\n `/${getRoutePrefixForDomainType()}/:domain`,\n scenarioScheduleCallbackRouter.routes(),\n scenarioScheduleCallbackRouter.allowedMethods()\n )\n } else {\n domainPrivateRouter.use(\n '',\n scenarioScheduleCallbackRouter.routes(),\n scenarioScheduleCallbackRouter.allowedMethods()\n )\n }\n})\n\nprocess.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {\n if (isPathBaseDomain) {\n domainPrivateRouter.use(\n `/${getRoutePrefixForDomainType()}/:domain`,\n scenarioViewRouter.routes(),\n scenarioViewRouter.allowedMethods()\n )\n } else {\n domainPrivateRouter.use('', scenarioViewRouter.routes(), scenarioViewRouter.allowedMethods())\n }\n})\n"]}
1
+ {"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;AAAA,6CAA4C;AAC5C,iDAAmE;AAEnE,+EAAsE;AACtE,yGAA+F;AAE/F,MAAM,gBAAgB,GAAG,CAAC,YAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;AAEjD,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,mBAAmB,EAAE,EAAE;IACrF,IAAI,gBAAgB,EAAE,CAAC;QACrB,mBAAmB,CAAC,GAAG,CACrB,IAAI,IAAA,mCAA2B,GAAE,UAAU,EAC3C,qEAA8B,CAAC,MAAM,EAAE,EACvC,qEAA8B,CAAC,cAAc,EAAE,CAChD,CAAA;IACH,CAAC;SAAM,CAAC;QACN,mBAAmB,CAAC,GAAG,CACrB,EAAE,EACF,qEAA8B,CAAC,MAAM,EAAE,EACvC,qEAA8B,CAAC,cAAc,EAAE,CAChD,CAAA;IACH,CAAC;AACH,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,uCAA8C,EAAE,CAAC,GAAG,EAAE,mBAAmB,EAAE,EAAE;IACtF,IAAI,gBAAgB,EAAE,CAAC;QACrB,mBAAmB,CAAC,GAAG,CACrB,IAAI,IAAA,mCAA2B,GAAE,UAAU,EAC3C,4CAAkB,CAAC,MAAM,EAAE,EAC3B,4CAAkB,CAAC,cAAc,EAAE,CACpC,CAAA;IACH,CAAC;SAAM,CAAC;QACN,mBAAmB,CAAC,GAAG,CAAC,EAAE,EAAE,4CAAkB,CAAC,MAAM,EAAE,EAAE,4CAAkB,CAAC,cAAc,EAAE,CAAC,CAAA;IAC/F,CAAC;AACH,CAAC,CAAC,CAAA","sourcesContent":["import { config } from '@things-factory/env'\nimport { getRoutePrefixForDomainType } from '@things-factory/shell'\n\nimport { scenarioViewRouter } from './routers/scenario-view-router.js'\nimport { scenarioScheduleCallbackRouter } from './routers/scenario-schedule-callback-router.js'\n\nconst isPathBaseDomain = !config.get('subdomain')\n\nprocess.on('bootstrap-module-domain-public-route' as any, (app, domainPrivateRouter) => {\n if (isPathBaseDomain) {\n domainPrivateRouter.use(\n `/${getRoutePrefixForDomainType()}/:domain`,\n scenarioScheduleCallbackRouter.routes(),\n scenarioScheduleCallbackRouter.allowedMethods()\n )\n } else {\n domainPrivateRouter.use(\n '',\n scenarioScheduleCallbackRouter.routes(),\n scenarioScheduleCallbackRouter.allowedMethods()\n )\n }\n})\n\nprocess.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {\n if (isPathBaseDomain) {\n domainPrivateRouter.use(\n `/${getRoutePrefixForDomainType()}/:domain`,\n scenarioViewRouter.routes(),\n scenarioViewRouter.allowedMethods()\n )\n } else {\n domainPrivateRouter.use('', scenarioViewRouter.routes(), scenarioViewRouter.allowedMethods())\n }\n})\n"]}
@@ -65,7 +65,9 @@ let ConnectionMutation = class ConnectionMutation {
65
65
  });
66
66
  await connection.connect();
67
67
  await repository.save(connection);
68
- return Object.assign(Object.assign({}, connection), { state: connection_manager_1.ConnectionManager.getConnectionInstance(connection) ? connection_type_1.ConnectionStatus.CONNECTED : connection_type_1.ConnectionStatus.DISCONNECTED });
68
+ return Object.assign(Object.assign({}, connection), { state: connection_manager_1.ConnectionManager.getConnectionInstance(connection)
69
+ ? connection_type_1.ConnectionStatus.CONNECTED
70
+ : connection_type_1.ConnectionStatus.DISCONNECTED });
69
71
  }
70
72
  async disconnectConnection(name, context) {
71
73
  const { domain } = context.state;
@@ -76,7 +78,9 @@ let ConnectionMutation = class ConnectionMutation {
76
78
  });
77
79
  await connection.disconnect();
78
80
  await repository.save(connection);
79
- return Object.assign(Object.assign({}, connection), { state: connection_manager_1.ConnectionManager.getConnectionInstance(connection) ? connection_type_1.ConnectionStatus.CONNECTED : connection_type_1.ConnectionStatus.DISCONNECTED });
81
+ return Object.assign(Object.assign({}, connection), { state: connection_manager_1.ConnectionManager.getConnectionInstance(connection)
82
+ ? connection_type_1.ConnectionStatus.CONNECTED
83
+ : connection_type_1.ConnectionStatus.DISCONNECTED });
80
84
  }
81
85
  async importConnections(connections, context) {
82
86
  const { tx, domain, user } = context.state;
@@ -105,6 +109,7 @@ let ConnectionMutation = class ConnectionMutation {
105
109
  exports.ConnectionMutation = ConnectionMutation;
106
110
  tslib_1.__decorate([
107
111
  (0, type_graphql_1.Directive)('@transaction'),
112
+ (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
108
113
  (0, type_graphql_1.Mutation)(returns => connection_type_1.Connection, { description: 'To create new connection' }),
109
114
  tslib_1.__param(0, (0, type_graphql_1.Arg)('connection')),
110
115
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -114,6 +119,7 @@ tslib_1.__decorate([
114
119
  ], ConnectionMutation.prototype, "createConnection", null);
115
120
  tslib_1.__decorate([
116
121
  (0, type_graphql_1.Directive)('@transaction'),
122
+ (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
117
123
  (0, type_graphql_1.Mutation)(returns => connection_type_1.Connection, { description: 'To modify connection information' }),
118
124
  tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
119
125
  tslib_1.__param(1, (0, type_graphql_1.Arg)('patch')),
@@ -124,6 +130,7 @@ tslib_1.__decorate([
124
130
  ], ConnectionMutation.prototype, "updateConnection", null);
125
131
  tslib_1.__decorate([
126
132
  (0, type_graphql_1.Directive)('@transaction'),
133
+ (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
127
134
  (0, type_graphql_1.Mutation)(returns => [connection_type_1.Connection], { description: "To modify multiple connections' information" }),
128
135
  tslib_1.__param(0, (0, type_graphql_1.Arg)('patches', type => [connection_type_1.ConnectionPatch])),
129
136
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -133,6 +140,7 @@ tslib_1.__decorate([
133
140
  ], ConnectionMutation.prototype, "updateMultipleConnection", null);
134
141
  tslib_1.__decorate([
135
142
  (0, type_graphql_1.Directive)('@transaction'),
143
+ (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
136
144
  (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete connection' }),
137
145
  tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
138
146
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -142,6 +150,7 @@ tslib_1.__decorate([
142
150
  ], ConnectionMutation.prototype, "deleteConnection", null);
143
151
  tslib_1.__decorate([
144
152
  (0, type_graphql_1.Directive)('@transaction'),
153
+ (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
145
154
  (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete multiple connections' }),
146
155
  tslib_1.__param(0, (0, type_graphql_1.Arg)('names', type => [String])),
147
156
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -150,6 +159,8 @@ tslib_1.__decorate([
150
159
  tslib_1.__metadata("design:returntype", Promise)
151
160
  ], ConnectionMutation.prototype, "deleteConnections", null);
152
161
  tslib_1.__decorate([
162
+ (0, type_graphql_1.Directive)('@transaction'),
163
+ (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
153
164
  (0, type_graphql_1.Mutation)(returns => connection_type_1.Connection, { description: 'To connect a connection' }),
154
165
  tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
155
166
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -158,6 +169,8 @@ tslib_1.__decorate([
158
169
  tslib_1.__metadata("design:returntype", Promise)
159
170
  ], ConnectionMutation.prototype, "connectConnection", null);
160
171
  tslib_1.__decorate([
172
+ (0, type_graphql_1.Directive)('@transaction'),
173
+ (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
161
174
  (0, type_graphql_1.Mutation)(returns => connection_type_1.Connection, { description: 'To disconnect a connection' }),
162
175
  tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
163
176
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -166,9 +179,8 @@ tslib_1.__decorate([
166
179
  tslib_1.__metadata("design:returntype", Promise)
167
180
  ], ConnectionMutation.prototype, "disconnectConnection", null);
168
181
  tslib_1.__decorate([
169
- (0, type_graphql_1.Directive)('@transaction')
170
- // @Directive('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true)')
171
- ,
182
+ (0, type_graphql_1.Directive)('@transaction'),
183
+ (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "mutation", domainOwnerGranted: true, superUserGranted: true)'),
172
184
  (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To import multiple connections' }),
173
185
  tslib_1.__param(0, (0, type_graphql_1.Arg)('connections', type => [connection_type_1.ConnectionPatch])),
174
186
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -1 +1 @@
1
- {"version":3,"file":"connection-mutation.js","sourceRoot":"","sources":["../../../server/service/connection/connection-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,iDAAqD;AAErD,wEAAmE;AACnE,uDAAgG;AAGzF,IAAM,kBAAkB,GAAxB,MAAM,kBAA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IACnD,mBAAA,IAAA,kBAAG,EAAC,MAAM,CAAC,CAAA;IAAgB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;8DAgB3D;AAKK;IAHL,IAAA,wBAAS,EAAC,cAAc,CAAC;IAC1B,oGAAoG;;IACnG,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;IACvD,mBAAA,IAAA,kBAAG,EAAC,aAAa,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,iCAAe,CAAC,CAAC,CAAA;IAA6B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DA2CvG;6BAnLU,kBAAkB;IAD9B,IAAA,uBAAQ,EAAC,4BAAU,CAAC;GACR,kBAAkB,CAoL9B","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine/connection-manager'\nimport { Connection, ConnectionPatch, ConnectionStatus, NewConnection } from './connection-type'\n\n@Resolver(Connection)\nexport class ConnectionMutation {\n @Directive('@transaction')\n @Mutation(returns => Connection, { description: 'To create new connection' })\n async createConnection(@Arg('connection') connection: NewConnection, @Ctx() context: ResolverContext): Promise<Connection> {\n const { domain, user, tx } = context.state\n\n return await tx.getRepository(Connection).save({\n ...connection,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => Connection, { description: 'To modify connection information' })\n async updateConnection(@Arg('name') name: string, @Arg('patch') patch: ConnectionPatch, @Ctx() context: ResolverContext): Promise<Connection> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(Connection)\n const connection = await repository.findOne({\n where: { domain: { id: domain.id }, name }\n })\n\n return await repository.save({\n ...connection,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Mutation(returns => [Connection], { description: \"To modify multiple connections' information\" })\n async updateMultipleConnection(@Arg('patches', type => [ConnectionPatch]) patches: ConnectionPatch[], @Ctx() context: ResolverContext): Promise<Connection[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const connectionRepo = tx.getRepository(Connection)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await connectionRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const newRecord = _updateRecords[i]\n const connection = await connectionRepo.findOneBy({ id: newRecord.id })\n\n const result = await connectionRepo.save({\n ...connection,\n ...newRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete connection' })\n async deleteConnection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Connection).delete({ domain: { id: domain.id }, name })\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple connections' })\n async deleteConnections(@Arg('names', type => [String]) names: string[], @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Connection).delete({\n domain: { id: domain.id },\n name: In(names)\n })\n\n return true\n }\n\n @Mutation(returns => Connection, { description: 'To connect a connection' })\n async connectConnection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Connection> {\n const { domain } = context.state\n var repository = getRepository(Connection)\n var connection = await repository.findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['domain', 'edge']\n })\n\n await connection.connect()\n await repository.save(connection)\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection) ? ConnectionStatus.CONNECTED : ConnectionStatus.DISCONNECTED\n } as Connection\n }\n\n @Mutation(returns => Connection, { description: 'To disconnect a connection' })\n async disconnectConnection(@Arg('name') name: string, @Ctx() context: ResolverContext) {\n const { domain } = context.state\n\n var repository = getRepository(Connection)\n var connection = await repository.findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['domain', 'edge']\n })\n\n await connection.disconnect()\n await repository.save(connection)\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection) ? ConnectionStatus.CONNECTED : ConnectionStatus.DISCONNECTED\n }\n }\n\n @Directive('@transaction')\n // @Directive('@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To import multiple connections' })\n async importConnections(@Arg('connections', type => [ConnectionPatch]) connections: Connection[], @Ctx() context: ResolverContext): Promise<boolean> {\n const { tx, domain, user } = context.state\n\n const repository = tx.getRepository(Connection)\n\n await Promise.all(\n connections.map(async (connection: Connection) => {\n const { id, name } = connection\n\n if (id) {\n const sameId = await repository.findOneBy({ id })\n\n if (sameId) {\n if (sameId.domainId != domain.id) {\n throw `Connection with id '${id}:${name}' is already taken by another domain`\n }\n\n const sameName = await repository.findOneBy({ domain: { id: domain.id }, name })\n if (sameName && sameName.id != id) {\n throw `Connection with name '${name}' is already taken by another connection`\n }\n\n await repository.save({\n ...sameId,\n ...connection,\n domain,\n updater: user\n })\n\n return\n }\n }\n\n await repository.save({\n ...connection,\n domain,\n updater: user,\n creator: user\n })\n })\n )\n\n return true\n }\n}\n"]}
1
+ {"version":3,"file":"connection-mutation.js","sourceRoot":"","sources":["../../../server/service/connection/connection-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,iDAAqD;AAErD,wEAAmE;AACnE,uDAAgG;AAGzF,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAMvB,AAAN,KAAK,CAAC,gBAAgB,CACD,UAAyB,EACrC,OAAwB;QAE/B,MAAM,EAAE,MAAM,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,CAAC,CAAA;IAAgB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DAiBxD;AAOK;IALL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EACR,6GAA6G,CAC9G;IACA,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,4BAAU,EAAE,EAAE,WAAW,EAAE,4BAA4B,EAAE,CAAC;IACnD,mBAAA,IAAA,kBAAG,EAAC,MAAM,CAAC,CAAA;IAAgB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;8DAkB3D;AAOK;IALL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EACR,6GAA6G,CAC9G;IACA,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;IAE7E,mBAAA,IAAA,kBAAG,EAAC,aAAa,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,iCAAe,CAAC,CAAC,CAAA;IAC7C,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DA4CP;6BAhOU,kBAAkB;IAD9B,IAAA,uBAAQ,EAAC,4BAAU,CAAC;GACR,kBAAkB,CAiO9B","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine/connection-manager'\nimport { Connection, ConnectionPatch, ConnectionStatus, NewConnection } from './connection-type'\n\n@Resolver(Connection)\nexport class ConnectionMutation {\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'To create new connection' })\n async createConnection(\n @Arg('connection') connection: NewConnection,\n @Ctx() context: ResolverContext\n ): Promise<Connection> {\n const { domain, user, tx } = context.state\n\n return await tx.getRepository(Connection).save({\n ...connection,\n domain,\n creator: user,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'To modify connection information' })\n async updateConnection(\n @Arg('name') name: string,\n @Arg('patch') patch: ConnectionPatch,\n @Ctx() context: ResolverContext\n ): Promise<Connection> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(Connection)\n const connection = await repository.findOne({\n where: { domain: { id: domain.id }, name }\n })\n\n return await repository.save({\n ...connection,\n ...patch,\n updater: user\n })\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => [Connection], { description: \"To modify multiple connections' information\" })\n async updateMultipleConnection(\n @Arg('patches', type => [ConnectionPatch]) patches: ConnectionPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Connection[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const connectionRepo = tx.getRepository(Connection)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await connectionRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const newRecord = _updateRecords[i]\n const connection = await connectionRepo.findOneBy({ id: newRecord.id })\n\n const result = await connectionRepo.save({\n ...connection,\n ...newRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Boolean, { description: 'To delete connection' })\n async deleteConnection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Connection).delete({ domain: { id: domain.id }, name })\n return true\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Boolean, { description: 'To delete multiple connections' })\n async deleteConnections(\n @Arg('names', type => [String]) names: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Connection).delete({\n domain: { id: domain.id },\n name: In(names)\n })\n\n return true\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'To connect a connection' })\n async connectConnection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Connection> {\n const { domain } = context.state\n var repository = getRepository(Connection)\n var connection = await repository.findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['domain', 'edge']\n })\n\n await connection.connect()\n await repository.save(connection)\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n } as Connection\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Connection, { description: 'To disconnect a connection' })\n async disconnectConnection(@Arg('name') name: string, @Ctx() context: ResolverContext) {\n const { domain } = context.state\n\n var repository = getRepository(Connection)\n var connection = await repository.findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['domain', 'edge']\n })\n\n await connection.disconnect()\n await repository.save(connection)\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n }\n }\n\n @Directive('@transaction')\n @Directive(\n '@privilege(category: \"connection\", privilege: \"mutation\", domainOwnerGranted: true, superUserGranted: true)'\n )\n @Mutation(returns => Boolean, { description: 'To import multiple connections' })\n async importConnections(\n @Arg('connections', type => [ConnectionPatch]) connections: Connection[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { tx, domain, user } = context.state\n\n const repository = tx.getRepository(Connection)\n\n await Promise.all(\n connections.map(async (connection: Connection) => {\n const { id, name } = connection\n\n if (id) {\n const sameId = await repository.findOneBy({ id })\n\n if (sameId) {\n if (sameId.domainId != domain.id) {\n throw `Connection with id '${id}:${name}' is already taken by another domain`\n }\n\n const sameName = await repository.findOneBy({ domain: { id: domain.id }, name })\n if (sameName && sameName.id != id) {\n throw `Connection with name '${name}' is already taken by another connection`\n }\n\n await repository.save({\n ...sameId,\n ...connection,\n domain,\n updater: user\n })\n\n return\n }\n }\n\n await repository.save({\n ...connection,\n domain,\n updater: user,\n creator: user\n })\n })\n )\n\n return true\n }\n}\n"]}
@@ -55,6 +55,7 @@ let ConnectionQuery = class ConnectionQuery {
55
55
  };
56
56
  exports.ConnectionQuery = ConnectionQuery;
57
57
  tslib_1.__decorate([
58
+ (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "query", domainOwnerGranted: true, superUserGranted: true)'),
58
59
  (0, type_graphql_1.Query)(returns => connection_type_1.Connection, { description: 'To fetch a connection' }),
59
60
  tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
60
61
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -63,6 +64,7 @@ tslib_1.__decorate([
63
64
  tslib_1.__metadata("design:returntype", Promise)
64
65
  ], ConnectionQuery.prototype, "connection", null);
65
66
  tslib_1.__decorate([
67
+ (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "query", domainOwnerGranted: true, superUserGranted: true)'),
66
68
  (0, type_graphql_1.Query)(returns => connection_type_1.ConnectionList, { description: 'To fetch multiple connections' }),
67
69
  tslib_1.__param(0, (0, type_graphql_1.Args)(type => shell_1.ListParam)),
68
70
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -71,6 +73,7 @@ tslib_1.__decorate([
71
73
  tslib_1.__metadata("design:returntype", Promise)
72
74
  ], ConnectionQuery.prototype, "connections", null);
73
75
  tslib_1.__decorate([
76
+ (0, type_graphql_1.Directive)('@privilege(category: "connection", privilege: "query", domainOwnerGranted: true, superUserGranted: true)'),
74
77
  (0, type_graphql_1.Query)(returns => connection_type_1.ConnectionState, { description: 'To fetch the state of a connection' }),
75
78
  tslib_1.__param(0, (0, type_graphql_1.Arg)('name')),
76
79
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -1 +1 @@
1
- {"version":3,"file":"connection-query.js","sourceRoot":"","sources":["../../../server/service/connection/connection-query.ts"],"names":[],"mappings":";;;;AAAA,+CAAmF;AAEnF,yDAA2D;AAC3D,iDAAuG;AAEvG,wEAAmE;AACnE,uDAAiG;AAG1F,IAAM,eAAe,GAArB,MAAM,eAAe;IAEpB,AAAN,KAAK,CAAC,UAAU,CAAc,IAAY,EAAS,OAAwB;QACzE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,IAAI,UAAU,GAAG,MAAM,IAAA,qBAAa,EAAC,4BAAU,CAAC,CAAC,OAAO,CAAC;YACvD,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE;YAC1C,SAAS,EAAE,CAAC,QAAQ,CAAC;SACtB,CAAC,CAAA;QAEF,OAAO,gCACF,UAAU,KACb,KAAK,EAAE,sCAAiB,CAAC,qBAAqB,CAAC,UAAU,CAAC;gBACxD,CAAC,CAAC,kCAAgB,CAAC,SAAS;gBAC5B,CAAC,CAAC,kCAAgB,CAAC,YAAY,GACpB,CAAA;IACjB,CAAC;IAGK,AAAN,KAAK,CAAC,WAAW,CACU,MAAiB,EACnC,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,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,oCAAoC,EAAE,CAAC;IACnE,mBAAA,IAAA,kBAAG,EAAC,MAAM,CAAC,CAAA;IAAgB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;4CAA4B,iCAAe;2DAShG;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IAClB,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAa,4BAAU;;2CAExC;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IAChB,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAa,4BAAU;;6CAI1C;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAa,4BAAU;;8CAE3C;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAa,4BAAU;;8CAE3C;0BA5EU,eAAe;IAD3B,IAAA,uBAAQ,EAAC,4BAAU,CAAC;GACR,eAAe,CA6E3B","sourcesContent":["import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'\n\nimport { Appliance, User } from '@things-factory/auth-base'\nimport { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine/connection-manager'\nimport { Connection, ConnectionList, ConnectionState, ConnectionStatus } from './connection-type'\n\n@Resolver(Connection)\nexport class ConnectionQuery {\n @Query(returns => Connection, { description: 'To fetch a connection' })\n async connection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Connection> {\n const { domain } = context.state\n\n var connection = await getRepository(Connection).findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['domain']\n })\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n } as Connection\n }\n\n @Query(returns => ConnectionList, { description: 'To fetch multiple connections' })\n async connections(\n @Args(type => ListParam) params: ListParam,\n @Ctx() context: ResolverContext\n ): Promise<ConnectionList> {\n const { domain } = context.state\n\n const queryBuilder = getQueryBuilderFromListParams({\n repository: getRepository(Connection),\n params,\n domain,\n alias: 'connection',\n searchables: ['name', 'description', 'type', 'endpoint']\n })\n\n const [items, total] = await queryBuilder.leftJoinAndSelect('connection.domain', 'domain').getManyAndCount()\n\n items.forEach(connection => {\n connection['state'] = ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n })\n\n return { items, total }\n }\n\n @Query(returns => ConnectionState, { description: 'To fetch the state of a connection' })\n fetchConnectionState(@Arg('name') name: string, @Ctx() context: ResolverContext): ConnectionState {\n const { domain } = context.state\n\n const connection = ConnectionManager.getConnectionInstanceEntityByName(domain, name)\n\n return {\n ...connection,\n state: connection ? ConnectionStatus.CONNECTED : ConnectionStatus.DISCONNECTED\n }\n }\n\n @FieldResolver(type => Domain)\n async edge(@Root() connection: Connection) {\n return connection.edgeId && (await getRepository(Appliance).findOneBy({ id: connection.edgeId }))\n }\n\n @FieldResolver(type => Domain)\n async domain(@Root() connection: Connection) {\n return (\n connection.domain || (connection.domainId && (await getRepository(Domain).findOneBy({ id: connection.domainId })))\n )\n }\n\n @FieldResolver(type => User)\n async updater(@Root() connection: Connection): Promise<User> {\n return connection.updaterId && (await getRepository(User).findOneBy({ id: connection.updaterId }))\n }\n\n @FieldResolver(type => User)\n async creator(@Root() connection: Connection): Promise<User> {\n return connection.creatorId && (await getRepository(User).findOneBy({ id: connection.creatorId }))\n }\n}\n"]}
1
+ {"version":3,"file":"connection-query.js","sourceRoot":"","sources":["../../../server/service/connection/connection-query.ts"],"names":[],"mappings":";;;;AAAA,+CAA8F;AAE9F,yDAA2D;AAC3D,iDAAuG;AAEvG,wEAAmE;AACnE,uDAAiG;AAG1F,IAAM,eA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E,CAAC,gBAAI,CAAC;IACb,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAa,4BAAU;;8CAE3C;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAa,4BAAU;;8CAE3C;0BA/EU,eAAe;IAD3B,IAAA,uBAAQ,EAAC,4BAAU,CAAC;GACR,eAAe,CAgF3B","sourcesContent":["import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'\n\nimport { Appliance, User } from '@things-factory/auth-base'\nimport { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine/connection-manager'\nimport { Connection, ConnectionList, ConnectionState, ConnectionStatus } from './connection-type'\n\n@Resolver(Connection)\nexport class ConnectionQuery {\n @Directive('@privilege(category: \"connection\", privilege: \"query\", domainOwnerGranted: true, superUserGranted: true)')\n @Query(returns => Connection, { description: 'To fetch a connection' })\n async connection(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<Connection> {\n const { domain } = context.state\n\n var connection = await getRepository(Connection).findOne({\n where: { domain: { id: domain.id }, name },\n relations: ['domain']\n })\n\n return {\n ...connection,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n } as Connection\n }\n\n @Directive('@privilege(category: \"connection\", privilege: \"query\", domainOwnerGranted: true, superUserGranted: true)')\n @Query(returns => ConnectionList, { description: 'To fetch multiple connections' })\n async connections(\n @Args(type => ListParam) params: ListParam,\n @Ctx() context: ResolverContext\n ): Promise<ConnectionList> {\n const { domain } = context.state\n\n const queryBuilder = getQueryBuilderFromListParams({\n repository: getRepository(Connection),\n params,\n domain,\n alias: 'connection',\n searchables: ['name', 'description', 'type', 'endpoint']\n })\n\n const [items, total] = await queryBuilder.leftJoinAndSelect('connection.domain', 'domain').getManyAndCount()\n\n items.forEach(connection => {\n connection['state'] = ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED\n })\n\n return { items, total }\n }\n\n @Directive('@privilege(category: \"connection\", privilege: \"query\", domainOwnerGranted: true, superUserGranted: true)')\n @Query(returns => ConnectionState, { description: 'To fetch the state of a connection' })\n fetchConnectionState(@Arg('name') name: string, @Ctx() context: ResolverContext): ConnectionState {\n const { domain } = context.state\n\n const connection = ConnectionManager.getConnectionInstanceEntityByName(domain, name)\n\n return {\n ...connection,\n state: connection ? ConnectionStatus.CONNECTED : ConnectionStatus.DISCONNECTED\n }\n }\n\n @FieldResolver(type => Domain)\n async edge(@Root() connection: Connection) {\n return connection.edgeId && (await getRepository(Appliance).findOneBy({ id: connection.edgeId }))\n }\n\n @FieldResolver(type => Domain)\n async domain(@Root() connection: Connection) {\n return (\n connection.domain || (connection.domainId && (await getRepository(Domain).findOneBy({ id: connection.domainId })))\n )\n }\n\n @FieldResolver(type => User)\n async updater(@Root() connection: Connection): Promise<User> {\n return connection.updaterId && (await getRepository(User).findOneBy({ id: connection.updaterId }))\n }\n\n @FieldResolver(type => User)\n async creator(@Root() connection: Connection): Promise<User> {\n return connection.creatorId && (await getRepository(User).findOneBy({ id: connection.creatorId }))\n }\n}\n"]}