@things-factory/integration-base 9.0.0-beta.8 → 9.0.0-beta.80

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 (116) hide show
  1. package/dist-server/controllers/publish-data.js +7 -2
  2. package/dist-server/controllers/publish-data.js.map +1 -1
  3. package/dist-server/engine/analyzer/analyze-integration.js +1 -1
  4. package/dist-server/engine/analyzer/analyze-integration.js.map +1 -1
  5. package/dist-server/engine/connection-manager.js +41 -40
  6. package/dist-server/engine/connection-manager.js.map +1 -1
  7. package/dist-server/engine/connector/graphql-connector.js +4 -1
  8. package/dist-server/engine/connector/graphql-connector.js.map +1 -1
  9. package/dist-server/engine/connector/headless-connector.js +1 -2
  10. package/dist-server/engine/connector/headless-connector.js.map +1 -1
  11. package/dist-server/engine/connector/http-connector.js +5 -1
  12. package/dist-server/engine/connector/http-connector.js.map +1 -1
  13. package/dist-server/engine/connector/operato-connector.js +10 -8
  14. package/dist-server/engine/connector/operato-connector.js.map +1 -1
  15. package/dist-server/engine/connector/oracle-connector.js +2 -2
  16. package/dist-server/engine/connector/oracle-connector.js.map +1 -1
  17. package/dist-server/engine/connector/postgresql-connector.js +3 -3
  18. package/dist-server/engine/connector/postgresql-connector.js.map +1 -1
  19. package/dist-server/engine/connector/proxy-connector.js +1 -1
  20. package/dist-server/engine/connector/proxy-connector.js.map +1 -1
  21. package/dist-server/engine/index.d.ts +2 -2
  22. package/dist-server/engine/index.js +2 -2
  23. package/dist-server/engine/index.js.map +1 -1
  24. package/dist-server/engine/scenario-engine.js +10 -7
  25. package/dist-server/engine/scenario-engine.js.map +1 -1
  26. package/dist-server/engine/task/headless-post.js +3 -1
  27. package/dist-server/engine/task/headless-post.js.map +1 -1
  28. package/dist-server/engine/task/headless-scrap.js +36 -4
  29. package/dist-server/engine/task/headless-scrap.js.map +1 -1
  30. package/dist-server/engine/task/http-get.js +4 -1
  31. package/dist-server/engine/task/http-get.js.map +1 -1
  32. package/dist-server/engine/task/http-post.js +4 -1
  33. package/dist-server/engine/task/http-post.js.map +1 -1
  34. package/dist-server/engine/task/mqtt-publish.js +29 -6
  35. package/dist-server/engine/task/mqtt-publish.js.map +1 -1
  36. package/dist-server/engine/task/mqtt-subscribe.d.ts +84 -0
  37. package/dist-server/engine/task/mqtt-subscribe.js +197 -79
  38. package/dist-server/engine/task/mqtt-subscribe.js.map +1 -1
  39. package/dist-server/engine/task/mssql-procedure.js +1 -1
  40. package/dist-server/engine/task/mssql-procedure.js.map +1 -1
  41. package/dist-server/engine/task/oracle-procedure.js +10 -10
  42. package/dist-server/engine/task/oracle-procedure.js.map +1 -1
  43. package/dist-server/engine/task/pick-pending-scenario.js +5 -1
  44. package/dist-server/engine/task/pick-pending-scenario.js.map +1 -1
  45. package/dist-server/engine/task/state-group-read.js +1 -2
  46. package/dist-server/engine/task/state-group-read.js.map +1 -1
  47. package/dist-server/engine/task/state-read.js +1 -2
  48. package/dist-server/engine/task/state-read.js.map +1 -1
  49. package/dist-server/engine/task/state-write.js +1 -2
  50. package/dist-server/engine/task/state-write.js.map +1 -1
  51. package/dist-server/engine/task/stop-scenario.js +3 -3
  52. package/dist-server/engine/task/stop-scenario.js.map +1 -1
  53. package/dist-server/engine/task/sub-scenario.js +5 -2
  54. package/dist-server/engine/task/sub-scenario.js.map +1 -1
  55. package/dist-server/engine/task/switch-range-scenario.js +5 -2
  56. package/dist-server/engine/task/switch-range-scenario.js.map +1 -1
  57. package/dist-server/engine/task/switch-scenario.js +5 -2
  58. package/dist-server/engine/task/switch-scenario.js.map +1 -1
  59. package/dist-server/engine/task/variables.js +1 -1
  60. package/dist-server/engine/task/variables.js.map +1 -1
  61. package/dist-server/engine/task-registry.js +4 -2
  62. package/dist-server/engine/task-registry.js.map +1 -1
  63. package/dist-server/index.d.ts +6 -6
  64. package/dist-server/index.js +10 -10
  65. package/dist-server/index.js.map +1 -1
  66. package/dist-server/routers/scenario-schedule-callback-router.js +2 -2
  67. package/dist-server/routers/scenario-schedule-callback-router.js.map +1 -1
  68. package/dist-server/routes.js +8 -7
  69. package/dist-server/routes.js.map +1 -1
  70. package/dist-server/service/connection/connection-mutation.d.ts +3 -1
  71. package/dist-server/service/connection/connection-mutation.js +59 -13
  72. package/dist-server/service/connection/connection-mutation.js.map +1 -1
  73. package/dist-server/service/connection/connection-query.js +12 -3
  74. package/dist-server/service/connection/connection-query.js.map +1 -1
  75. package/dist-server/service/connection/connection-subscription.js +10 -8
  76. package/dist-server/service/connection/connection-subscription.js.map +1 -1
  77. package/dist-server/service/connection/connection-type.d.ts +14 -3
  78. package/dist-server/service/connection/connection-type.js +29 -15
  79. package/dist-server/service/connection/connection-type.js.map +1 -1
  80. package/dist-server/service/payload-log/payload-log-mutation.js +25 -7
  81. package/dist-server/service/payload-log/payload-log-mutation.js.map +1 -1
  82. package/dist-server/service/scenario/scenario-mutation.js +56 -12
  83. package/dist-server/service/scenario/scenario-mutation.js.map +1 -1
  84. package/dist-server/service/scenario/scenario-query.js +2 -3
  85. package/dist-server/service/scenario/scenario-query.js.map +1 -1
  86. package/dist-server/service/scenario/scenario.js +5 -5
  87. package/dist-server/service/scenario/scenario.js.map +1 -1
  88. package/dist-server/service/scenario-instance/scenario-instance-subscription.js +6 -8
  89. package/dist-server/service/scenario-instance/scenario-instance-subscription.js.map +1 -1
  90. package/dist-server/service/scenario-instance/scenario-instance-type.js +26 -30
  91. package/dist-server/service/scenario-instance/scenario-instance-type.js.map +1 -1
  92. package/dist-server/service/scenario-queue/scenario-queue-subscription.js +3 -4
  93. package/dist-server/service/scenario-queue/scenario-queue-subscription.js.map +1 -1
  94. package/dist-server/service/state-register/data-resolver.js +3 -4
  95. package/dist-server/service/state-register/data-resolver.js.map +1 -1
  96. package/dist-server/service/state-register/state-register-mutation.js +32 -9
  97. package/dist-server/service/state-register/state-register-mutation.js.map +1 -1
  98. package/dist-server/service/state-register/state-register-query.js +1 -1
  99. package/dist-server/service/state-register/state-register-query.js.map +1 -1
  100. package/dist-server/service/step/step-mutation.js +9 -3
  101. package/dist-server/service/step/step-mutation.js.map +1 -1
  102. package/dist-server/service/step/step-type.d.ts +11 -3
  103. package/dist-server/service/step/step-type.js +24 -5
  104. package/dist-server/service/step/step-type.js.map +1 -1
  105. package/dist-server/tsconfig.tsbuildinfo +1 -1
  106. package/helps/integration/task/headless-scrap.ja.md +11 -4
  107. package/helps/integration/task/headless-scrap.ko.md +12 -5
  108. package/helps/integration/task/headless-scrap.md +10 -3
  109. package/helps/integration/task/headless-scrap.ms.md +9 -2
  110. package/helps/integration/task/headless-scrap.zh.md +9 -2
  111. package/package.json +11 -11
  112. package/translations/en.json +6 -1
  113. package/translations/ja.json +6 -1
  114. package/translations/ko.json +6 -1
  115. package/translations/ms.json +6 -1
  116. package/translations/zh.json +6 -1
@@ -1 +1 @@
1
- {"version":3,"file":"http-post.js","sourceRoot":"","sources":["../../../server/engine/task/http-post.ts"],"names":[],"mappings":";;;AAAA,oEAA8B;AAC9B,6BAAyB;AACzB,eAAY;AACZ,iDAA8C;AAC9C,oDAA+C;AAC/C,8DAAyD;AACzD,0DAAyB;AAIzB,KAAK,UAAU,QAAQ,CAAC,IAAe,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAW;IAC9F,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,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AAE,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;oBACE,OAAO,EAAE,EAAE;oBACX,KAAK,EAAE,EAAE;iBACV;gBACD;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,QAAQ,CAAC,IAAI,GAAG,4BAA4B,CAAA;AAE5C,4BAAY,CAAC,mBAAmB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAA","sourcesContent":["import fetch from 'node-fetch'\nimport { URL } from 'url'\nimport 'ses'\nimport { access } from '@things-factory/utils'\nimport { TaskRegistry } from '../task-registry'\nimport { ConnectionManager } from '../connection-manager'\nimport https from 'https'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\nasync function HttpPost(step: InputStep, { logger, data, domain, user, variables, lng }: 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 const compartment = new Compartment({\n domain,\n user,\n lng,\n data,\n variables,\n console\n })\n\n let evalPath\n try {\n evalPath = compartment.evaluate('`' + path + '`')\n } catch (err) {\n throw new Error(`Failed to evaluate path: ${err.message}`)\n }\n\n path = evalPath\n\n requestHeaders =\n requestHeaders &&\n Object.entries(requestHeaders as { [key: string]: string }).reduce((sum, [key, value]) => {\n try {\n sum[key] = compartment.evaluate('`' + value + '`')\n } catch (err) {\n throw new Error(`Failed to evaluate header value: ${err.message}`)\n }\n return sum\n }, {})\n\n var url = new URL(path, endpoint)\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 fetchOptions: 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 fetchOptions.agent = httpsAgent\n }\n\n var response = await fetch(url, fetchOptions)\n\n return {\n data:\n response.ok && response.headers.get('content-type').includes('application/json')\n ? await response.json()\n : await response.text()\n }\n}\n\nHttpPost.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\nHttpPost.help = 'integration/task/http-post'\n\nTaskRegistry.registerTaskHandler('http-post', HttpPost)\n"]}
1
+ {"version":3,"file":"http-post.js","sourceRoot":"","sources":["../../../server/engine/task/http-post.ts"],"names":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ChB,KAAK,EAAE,UAAU;KAClB;CACF,CAAA;AAED,QAAQ,CAAC,IAAI,GAAG,4BAA4B,CAAA;AAE5C,4BAAY,CAAC,mBAAmB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAA","sourcesContent":["import fetch from 'node-fetch'\nimport { URL } from 'url'\nimport 'ses'\nimport { access } from '@things-factory/utils'\nimport { TaskRegistry } from '../task-registry'\nimport { ConnectionManager } from '../connection-manager'\nimport https from 'https'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\nasync function HttpPost(step: InputStep, { logger, data, domain, user, variables, lng }: 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 const compartment = new Compartment({\n domain,\n user,\n lng,\n data,\n variables,\n console\n })\n\n let evalPath\n try {\n evalPath = compartment.evaluate('`' + path + '`')\n } catch (err) {\n throw new Error(`Failed to evaluate path: ${err.message}`)\n }\n\n path = evalPath\n\n requestHeaders =\n requestHeaders &&\n Object.entries(requestHeaders as { [key: string]: string }).reduce((sum, [key, value]) => {\n try {\n sum[key] = compartment.evaluate('`' + value + '`')\n } catch (err) {\n throw new Error(`Failed to evaluate header value: ${err.message}`)\n }\n return sum\n }, {})\n\n var url = new URL(path, endpoint)\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 fetchOptions: 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 fetchOptions.agent = httpsAgent\n }\n\n var response = await fetch(url, fetchOptions)\n\n return {\n data:\n response.ok && response.headers.get('content-type').includes('application/json')\n ? await response.json()\n : await response.text()\n }\n}\n\nHttpPost.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\nHttpPost.help = 'integration/task/http-post'\n\nTaskRegistry.registerTaskHandler('http-post', HttpPost)\n"]}
@@ -1,18 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const utils_1 = require("@things-factory/utils");
4
- const task_registry_1 = require("../task-registry");
5
- const connection_manager_1 = require("../connection-manager");
4
+ const task_registry_js_1 = require("../task-registry.js");
5
+ const connection_manager_js_1 = require("../connection-manager.js");
6
6
  async function MqttPublish(step, { logger, data, domain }) {
7
- var { connection: connectionName, params: { topic, accessor } } = step;
8
- const { client } = connection_manager_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
7
+ var { connection: connectionName, params: { topic, accessor, dataFormat = 'json' } } = step;
8
+ const { client } = connection_manager_js_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
9
9
  if (!client) {
10
10
  throw Error(`connection is not found : ${connectionName}`);
11
11
  }
12
12
  if (!topic || !accessor) {
13
13
  throw Error(`topic and accessor should be defined: : topic - '${topic}', accessor - '${accessor}'`);
14
14
  }
15
- var message = JSON.stringify((0, utils_1.access)(accessor, data));
15
+ var message = (0, utils_1.access)(accessor, data);
16
+ if (dataFormat === 'text') {
17
+ message = String(message);
18
+ }
19
+ else {
20
+ message = JSON.stringify(message);
21
+ }
16
22
  await client.publish(topic, message);
17
23
  return {
18
24
  data: message
@@ -28,8 +34,25 @@ MqttPublish.parameterSpec = [
28
34
  type: 'scenario-step-input',
29
35
  name: 'accessor',
30
36
  label: 'accessor'
37
+ },
38
+ {
39
+ type: 'select',
40
+ label: 'data-format',
41
+ name: 'dataFormat',
42
+ property: {
43
+ options: [
44
+ {
45
+ display: 'Plain Text',
46
+ value: 'text'
47
+ },
48
+ {
49
+ display: 'JSON',
50
+ value: 'json'
51
+ }
52
+ ]
53
+ }
31
54
  }
32
55
  ];
33
56
  MqttPublish.help = 'integration/task/mqtt-publish';
34
- task_registry_1.TaskRegistry.registerTaskHandler('mqtt-publish', MqttPublish);
57
+ task_registry_js_1.TaskRegistry.registerTaskHandler('mqtt-publish', MqttPublish);
35
58
  //# sourceMappingURL=mqtt-publish.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mqtt-publish.js","sourceRoot":"","sources":["../../../server/engine/task/mqtt-publish.ts"],"names":[],"mappings":";;AAAA,iDAA8C;AAC9C,oDAA+C;AAC/C,8DAAyD;AAIzD,KAAK,UAAU,WAAW,CAAC,IAAe,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAW;IAC3E,IAAI,EACF,UAAU,EAAE,cAAc,EAC1B,MAAM,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAC5B,GAAG,IAAI,CAAA;IAER,MAAM,EAAE,MAAM,EAAE,GAAG,sCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACxF,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,KAAK,CAAC,6BAA6B,cAAc,EAAE,CAAC,CAAA;IAC5D,CAAC;IAED,IAAI,CAAC,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC;QACxB,MAAM,KAAK,CAAC,oDAAoD,KAAK,kBAAkB,QAAQ,GAAG,CAAC,CAAA;IACrG,CAAC;IAED,IAAI,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAA,cAAM,EAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAA;IACpD,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAEpC,OAAO;QACL,IAAI,EAAE,OAAO;KACd,CAAA;AACH,CAAC;AAED,WAAW,CAAC,aAAa,GAAG;IAC1B;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;KACf;IACD;QACE,IAAI,EAAE,qBAAqB;QAC3B,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;KAClB;CACF,CAAA;AAED,WAAW,CAAC,IAAI,GAAG,+BAA+B,CAAA;AAElD,4BAAY,CAAC,mBAAmB,CAAC,cAAc,EAAE,WAAW,CAAC,CAAA","sourcesContent":["import { access } from '@things-factory/utils'\nimport { TaskRegistry } from '../task-registry'\nimport { ConnectionManager } from '../connection-manager'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\nasync function MqttPublish(step: InputStep, { logger, data, domain }: Context) {\n var {\n connection: connectionName,\n params: { topic, accessor }\n } = step\n\n const { client } = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n if (!client) {\n throw Error(`connection is not found : ${connectionName}`)\n }\n\n if (!topic || !accessor) {\n throw Error(`topic and accessor should be defined: : topic - '${topic}', accessor - '${accessor}'`)\n }\n\n var message = JSON.stringify(access(accessor, data))\n await client.publish(topic, message)\n\n return {\n data: message\n }\n}\n\nMqttPublish.parameterSpec = [\n {\n type: 'string',\n name: 'topic',\n label: 'topic'\n },\n {\n type: 'scenario-step-input',\n name: 'accessor',\n label: 'accessor'\n }\n]\n\nMqttPublish.help = 'integration/task/mqtt-publish'\n\nTaskRegistry.registerTaskHandler('mqtt-publish', Mqtt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IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;KAClB;IACD;QACE,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,aAAa;QACpB,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE;YACR,OAAO,EAAE;gBACP;oBACE,OAAO,EAAE,YAAY;oBACrB,KAAK,EAAE,MAAM;iBACd;gBACD;oBACE,OAAO,EAAE,MAAM;oBACf,KAAK,EAAE,MAAM;iBACd;aACF;SACF;KACF;CACF,CAAA;AAED,WAAW,CAAC,IAAI,GAAG,+BAA+B,CAAA;AAElD,+BAAY,CAAC,mBAAmB,CAAC,cAAc,EAAE,WAAW,CAAC,CAAA","sourcesContent":["import { access } from '@things-factory/utils'\nimport { TaskRegistry } from '../task-registry.js'\nimport { ConnectionManager } from '../connection-manager.js'\nimport { InputStep } from '../../service/step/step-type.js'\nimport { Context } from '../types.js'\n\nasync function MqttPublish(step: InputStep, { logger, data, domain }: Context) {\n var {\n connection: connectionName,\n params: { topic, accessor, dataFormat = 'json' }\n } = step\n\n const { client } = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n if (!client) {\n throw Error(`connection is not found : ${connectionName}`)\n }\n\n if (!topic || !accessor) {\n throw Error(`topic and accessor should be defined: : topic - '${topic}', accessor - '${accessor}'`)\n }\n\n var message = access(accessor, data)\n\n if (dataFormat === 'text') {\n message = String(message)\n } else {\n message = JSON.stringify(message)\n }\n\n await client.publish(topic, message)\n\n return {\n data: message\n }\n}\n\nMqttPublish.parameterSpec = [\n {\n type: 'string',\n name: 'topic',\n label: 'topic'\n },\n {\n type: 'scenario-step-input',\n name: 'accessor',\n label: 'accessor'\n },\n {\n type: 'select',\n label: 'data-format',\n name: 'dataFormat',\n property: {\n options: [\n {\n display: 'Plain Text',\n value: 'text'\n },\n {\n display: 'JSON',\n value: 'json'\n }\n ]\n }\n }\n]\n\nMqttPublish.help = 'integration/task/mqtt-publish'\n\nTaskRegistry.registerTaskHandler('mqtt-publish', MqttPublish)\n"]}
@@ -1 +1,85 @@
1
+ /**
2
+ * MQTT Subscribe Task
3
+ * ====================
4
+ *
5
+ * Pull-Based Message Consumption on MQTT:
6
+ * ---------------------------------------
7
+ * While MQTT is inherently a push-based protocol, this task implements a controlled,
8
+ * pull-style message consumption model. A message is only processed when the task is
9
+ * explicitly invoked (i.e., the consumer actively pulls one message at a time).
10
+ * This enables fine-grained control over message flow and avoids unintended buffering.
11
+ *
12
+ * Overview:
13
+ * ---------
14
+ * This task connects to a specified MQTT broker and subscribes to a given topic.
15
+ * It waits for a single message to arrive, resolves the result, and then removes
16
+ * its internal message handler. It is designed to be reentrant — each execution
17
+ * of this task handles exactly one message.
18
+ *
19
+ * This model is useful for applications where message processing must happen
20
+ * sequentially or be synchronized with external state (e.g., workflows or state machines).
21
+ *
22
+ * Key Features:
23
+ * -------------
24
+ * - One-message-per-invocation: each task call resolves with a single message.
25
+ * - Stateless message flow: the system does not queue or buffer messages locally.
26
+ * - Supports automatic re-subscription on reconnect, improving robustness in unstable networks.
27
+ * - Uses broker-level guarantees (QoS, retain) for durability and delivery control.
28
+ * - Supports multiple data formats (JSON, plain text) and adjustable QoS levels.
29
+ *
30
+ * MQTT Reconnection Handling:
31
+ * ---------------------------
32
+ * The task listens for 'connect' events on the MQTT client. When the client reconnects
33
+ * (e.g., after a dropped network), it automatically re-subscribes to all previously
34
+ * tracked topics. This ensures consistent behavior even in long-running systems or
35
+ * unstable network environments.
36
+ *
37
+ * If a disconnect occurs while a task is waiting for a message, the Promise remains
38
+ * pending until a message is received after reconnection, or until manually cleaned up
39
+ * via the task closure mechanism.
40
+ *
41
+ * How It Works:
42
+ * -------------
43
+ * 1. Retrieve an MQTT client using a named connection.
44
+ * 2. Subscribe to the specified topic (only once per topic per workflow).
45
+ * 3. Register a one-time message handler for the topic.
46
+ * 4. When a message is received:
47
+ * - It is parsed into the requested data format.
48
+ * - The task resolves with the parsed message.
49
+ * - The handler is immediately removed.
50
+ * 5. Re-subscribe to all topics upon reconnect.
51
+ * 6. Clean up all resources (subscription, handler, resolver) on task termination.
52
+ *
53
+ * Assumptions:
54
+ * ------------
55
+ * - Broker reliability is enforced via QoS ≥ 1 and/or retained messages.
56
+ * - Message loss may occur if a message arrives before re-invocation, unless the broker retains it.
57
+ * - The task caller is responsible for repeated invocations to consume additional messages.
58
+ * - MQTT clients are externally managed and assumed to reconnect automatically.
59
+ *
60
+ * Parameters:
61
+ * -----------
62
+ * - topic (string): MQTT topic to subscribe to.
63
+ * - dataFormat ('json' | 'text'): Describes how to parse the incoming message payload.
64
+ * - qos (0 | 1 | 2): Quality of Service level for the subscription (default: 1).
65
+ *
66
+ * Returns:
67
+ * --------
68
+ * - A Promise that resolves with the first received message:
69
+ * { data: any }
70
+ * - If the task is terminated before receiving a message:
71
+ * { data: null, terminated: true }
72
+ *
73
+ * Example:
74
+ * --------
75
+ * await MqttSubscribe({
76
+ * connection: 'my-mqtt',
77
+ * params: {
78
+ * topic: 'sensor/temperature',
79
+ * dataFormat: 'json',
80
+ * qos: 1
81
+ * },
82
+ * name: 'readTemperature'
83
+ * }, context)
84
+ */
1
85
  export {};
@@ -1,89 +1,198 @@
1
1
  "use strict";
2
+ /**
3
+ * MQTT Subscribe Task
4
+ * ====================
5
+ *
6
+ * Pull-Based Message Consumption on MQTT:
7
+ * ---------------------------------------
8
+ * While MQTT is inherently a push-based protocol, this task implements a controlled,
9
+ * pull-style message consumption model. A message is only processed when the task is
10
+ * explicitly invoked (i.e., the consumer actively pulls one message at a time).
11
+ * This enables fine-grained control over message flow and avoids unintended buffering.
12
+ *
13
+ * Overview:
14
+ * ---------
15
+ * This task connects to a specified MQTT broker and subscribes to a given topic.
16
+ * It waits for a single message to arrive, resolves the result, and then removes
17
+ * its internal message handler. It is designed to be reentrant — each execution
18
+ * of this task handles exactly one message.
19
+ *
20
+ * This model is useful for applications where message processing must happen
21
+ * sequentially or be synchronized with external state (e.g., workflows or state machines).
22
+ *
23
+ * Key Features:
24
+ * -------------
25
+ * - One-message-per-invocation: each task call resolves with a single message.
26
+ * - Stateless message flow: the system does not queue or buffer messages locally.
27
+ * - Supports automatic re-subscription on reconnect, improving robustness in unstable networks.
28
+ * - Uses broker-level guarantees (QoS, retain) for durability and delivery control.
29
+ * - Supports multiple data formats (JSON, plain text) and adjustable QoS levels.
30
+ *
31
+ * MQTT Reconnection Handling:
32
+ * ---------------------------
33
+ * The task listens for 'connect' events on the MQTT client. When the client reconnects
34
+ * (e.g., after a dropped network), it automatically re-subscribes to all previously
35
+ * tracked topics. This ensures consistent behavior even in long-running systems or
36
+ * unstable network environments.
37
+ *
38
+ * If a disconnect occurs while a task is waiting for a message, the Promise remains
39
+ * pending until a message is received after reconnection, or until manually cleaned up
40
+ * via the task closure mechanism.
41
+ *
42
+ * How It Works:
43
+ * -------------
44
+ * 1. Retrieve an MQTT client using a named connection.
45
+ * 2. Subscribe to the specified topic (only once per topic per workflow).
46
+ * 3. Register a one-time message handler for the topic.
47
+ * 4. When a message is received:
48
+ * - It is parsed into the requested data format.
49
+ * - The task resolves with the parsed message.
50
+ * - The handler is immediately removed.
51
+ * 5. Re-subscribe to all topics upon reconnect.
52
+ * 6. Clean up all resources (subscription, handler, resolver) on task termination.
53
+ *
54
+ * Assumptions:
55
+ * ------------
56
+ * - Broker reliability is enforced via QoS ≥ 1 and/or retained messages.
57
+ * - Message loss may occur if a message arrives before re-invocation, unless the broker retains it.
58
+ * - The task caller is responsible for repeated invocations to consume additional messages.
59
+ * - MQTT clients are externally managed and assumed to reconnect automatically.
60
+ *
61
+ * Parameters:
62
+ * -----------
63
+ * - topic (string): MQTT topic to subscribe to.
64
+ * - dataFormat ('json' | 'text'): Describes how to parse the incoming message payload.
65
+ * - qos (0 | 1 | 2): Quality of Service level for the subscription (default: 1).
66
+ *
67
+ * Returns:
68
+ * --------
69
+ * - A Promise that resolves with the first received message:
70
+ * { data: any }
71
+ * - If the task is terminated before receiving a message:
72
+ * { data: null, terminated: true }
73
+ *
74
+ * Example:
75
+ * --------
76
+ * await MqttSubscribe({
77
+ * connection: 'my-mqtt',
78
+ * params: {
79
+ * topic: 'sensor/temperature',
80
+ * dataFormat: 'json',
81
+ * qos: 1
82
+ * },
83
+ * name: 'readTemperature'
84
+ * }, context)
85
+ */
2
86
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const async_mqtt_1 = tslib_1.__importDefault(require("async-mqtt"));
5
- const task_registry_1 = require("../task-registry");
6
- const connection_manager_1 = require("../connection-manager");
7
- const utils_1 = require("@things-factory/utils");
87
+ const task_registry_js_1 = require("../task-registry.js");
88
+ const connection_manager_js_1 = require("../connection-manager.js");
8
89
  function convertDataFormat(data, format) {
9
- if (format == 'json') {
10
- return JSON.parse(data);
90
+ if (format === 'json') {
91
+ try {
92
+ return JSON.parse(data);
93
+ }
94
+ catch (e) {
95
+ console.error('JSON parse error:', e.message);
96
+ return data.toString();
97
+ }
11
98
  }
12
99
  else {
13
100
  return data.toString();
14
101
  }
15
102
  }
16
103
  async function MqttSubscribe(step, context) {
17
- const { connection: connectionName, params: { topic, dataFormat }, name } = step;
18
- const { domain, logger, closures, __mqtt_subscriber } = context;
19
- if (!__mqtt_subscriber) {
20
- context.__mqtt_subscriber = {};
104
+ const { connection: connectionName, params: { topic, dataFormat, qos = 1 }, name: stepName } = step;
105
+ const { domain, logger, closures } = context;
106
+ const { client } = connection_manager_js_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
107
+ if (!client)
108
+ throw new Error(`connection not found: ${connectionName}`);
109
+ if (!topic)
110
+ throw new Error(`Missing topic for connection: ${connectionName}`);
111
+ const subscriberId = `${domain}_${connectionName}_${topic}_${stepName}`;
112
+ context.__mqtt_subscriptions ??= new Set();
113
+ context.__mqtt_resolvers ??= new Map();
114
+ context.__mqtt_handlers ??= new Map();
115
+ // Setup MQTT client reconnect/resubscribe handlers only once
116
+ if (!context.__mqtt_event_hooked) {
117
+ client.on('connect', async () => {
118
+ logger.info('[MQTT] Reconnected. Resubscribing to topics...');
119
+ for (const t of context.__mqtt_subscriptions) {
120
+ try {
121
+ await client.subscribe(t, { qos });
122
+ logger.info(`[MQTT] Resubscribed to topic: ${t}`);
123
+ }
124
+ catch (e) {
125
+ logger.error(`[MQTT] Failed to resubscribe to topic ${t}: ${e.message}`);
126
+ }
127
+ }
128
+ });
129
+ client.on('offline', () => {
130
+ logger.warn('[MQTT] Client offline');
131
+ });
132
+ client.on('close', () => {
133
+ logger.warn('[MQTT] Connection closed');
134
+ });
135
+ client.on('error', err => {
136
+ logger.error(`[MQTT] Error: ${err.message}`);
137
+ });
138
+ context.__mqtt_event_hooked = true;
21
139
  }
22
- const { connection: { endpoint: uri, params: { user, password } } } = connection_manager_1.ConnectionManager.getConnectionInstanceByName(domain, connectionName);
23
- if (!topic) {
24
- throw Error(`topic is not found for ${connectionName}`);
140
+ // Subscribe if not already done
141
+ if (!context.__mqtt_subscriptions.has(topic)) {
142
+ await client.subscribe(topic, { qos: Number(qos) });
143
+ context.__mqtt_subscriptions.add(topic);
144
+ logger.info(`Subscribed to topic: ${topic} (QoS: ${qos})`);
25
145
  }
26
- /*
27
- * 1. subscriber list에서 subscriber를 찾는다. 없으면, 생성한다.
28
- * 2. client.once(...)로 메시지를 취한다.
29
- *
30
- * TODO 동일 브로커의 다중 subscribe 태스크에 대해서 완벽한 지원을 해야한다.
31
- * - 현재는 여러 태스크가 동일 topic을 subscribe 하는 경우에 정상동작하지 않을 것이다.
32
- */
33
- if (!context.__mqtt_subscriber[name]) {
34
- try {
35
- var broker = null;
36
- if (user && password) {
37
- broker = await async_mqtt_1.default.connectAsync(uri, { username: user, password: password });
38
- }
39
- else {
40
- broker = await async_mqtt_1.default.connectAsync(uri);
146
+ // Remove previous handler for this step
147
+ if (context.__mqtt_handlers.has(subscriberId)) {
148
+ const removeHandler = context.__mqtt_handlers.get(subscriberId);
149
+ removeHandler?.();
150
+ context.__mqtt_handlers.delete(subscriberId);
151
+ }
152
+ return new Promise(resolve => {
153
+ context.__mqtt_resolvers.set(subscriberId, resolve);
154
+ const messageHandler = (messageTopic, message) => {
155
+ if (messageTopic !== topic)
156
+ return;
157
+ const converted = convertDataFormat(message, dataFormat);
158
+ const resolver = context.__mqtt_resolvers.get(subscriberId);
159
+ if (resolver) {
160
+ context.__mqtt_resolvers.delete(subscriberId);
161
+ resolver({ data: converted });
162
+ client.removeListener('message', messageHandler);
163
+ context.__mqtt_handlers.delete(subscriberId);
41
164
  }
42
- logger.info(`mqtt-connector connection(${connectionName}:${uri}) is connected`);
43
- await broker.subscribe(topic);
44
- logger.info(`success subscribing topic '${topic}'`);
45
- var TOPIC;
46
- var MESSAGE;
47
- context.__mqtt_subscriber[name] = async () => {
48
- while (!MESSAGE) {
49
- await (0, utils_1.sleep)(100);
165
+ };
166
+ client.on('message', messageHandler);
167
+ context.__mqtt_handlers.set(subscriberId, () => {
168
+ client.removeListener('message', messageHandler);
169
+ });
170
+ closures.push(async () => {
171
+ try {
172
+ if (context.__mqtt_subscriptions?.has(topic)) {
173
+ await client.unsubscribe(topic);
174
+ context.__mqtt_subscriptions.delete(topic);
175
+ logger.info(`Unsubscribed from topic: ${topic}`);
50
176
  }
51
- var topic = TOPIC;
52
- var message = MESSAGE;
53
- TOPIC = null;
54
- MESSAGE = null;
55
- return {
56
- topic,
57
- message
58
- };
59
- };
60
- broker.on('message', async (messageTopic, message) => {
61
- if (topic !== messageTopic) {
62
- return;
177
+ if (context.__mqtt_handlers?.has(subscriberId)) {
178
+ const remove = context.__mqtt_handlers.get(subscriberId);
179
+ remove?.();
180
+ context.__mqtt_handlers.delete(subscriberId);
63
181
  }
64
- TOPIC = topic;
65
- MESSAGE = convertDataFormat(message, dataFormat);
66
- // logger.info(`mqtt-subscribe :\n'${message.toString()}'`)
67
- });
68
- closures.push(async () => {
69
- try {
70
- broker && (await broker.end());
71
- logger.info(`mqtt-connector connection(${connectionName}:${uri}) is disconnected`);
72
- }
73
- catch (e) {
74
- logger.error(e);
182
+ if (context.__mqtt_resolvers?.has(subscriberId)) {
183
+ const resolver = context.__mqtt_resolvers.get(subscriberId);
184
+ resolver?.({ data: null, terminated: true });
185
+ context.__mqtt_resolvers.delete(subscriberId);
75
186
  }
76
- });
77
- }
78
- catch (e) {
79
- logger.error(e);
80
- }
81
- }
82
- var { message } = await context.__mqtt_subscriber[name]();
83
- return {
84
- data: message
85
- };
187
+ }
188
+ catch (e) {
189
+ logger.error(`MQTT cleanup error: ${e.message}`);
190
+ }
191
+ });
192
+ logger.info(`Waiting for MQTT message on topic: ${topic}`);
193
+ });
86
194
  }
195
+ // Task parameter definitions for UI or DSL support
87
196
  MqttSubscribe.parameterSpec = [
88
197
  {
89
198
  type: 'string',
@@ -96,18 +205,27 @@ MqttSubscribe.parameterSpec = [
96
205
  name: 'dataFormat',
97
206
  property: {
98
207
  options: [
99
- {
100
- display: 'Plain Text',
101
- value: 'text'
102
- },
103
- {
104
- display: 'JSON',
105
- value: 'json'
106
- }
208
+ { display: '', value: undefined },
209
+ { display: 'Plain Text', value: 'text' },
210
+ { display: 'JSON', value: 'json' }
211
+ ]
212
+ }
213
+ },
214
+ {
215
+ type: 'select',
216
+ label: 'QoS',
217
+ name: 'qos',
218
+ property: {
219
+ options: [
220
+ { display: '', value: undefined },
221
+ { display: '0 (at most once)', value: 0 },
222
+ { display: '1 (at least once)', value: 1 },
223
+ { display: '2 (exactly once)', value: 2 }
107
224
  ]
108
225
  }
109
226
  }
110
227
  ];
111
228
  MqttSubscribe.help = 'integration/task/mqtt-subscribe';
112
- task_registry_1.TaskRegistry.registerTaskHandler('mqtt-subscribe', MqttSubscribe);
229
+ // Register task with runtime registry
230
+ task_registry_js_1.TaskRegistry.registerTaskHandler('mqtt-subscribe', MqttSubscribe);
113
231
  //# sourceMappingURL=mqtt-subscribe.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mqtt-subscribe.js","sourceRoot":"","sources":["../../../server/engine/task/mqtt-subscribe.ts"],"names":[],"mappings":";;;AAAA,oEAA6B;AAE7B,oDAA+C;AAC/C,8DAAyD;AACz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MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;gBACjB,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC;IACH,CAAC;IAED,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAA;IAEzD,OAAO;QACL,IAAI,EAAE,OAAO;KACd,CAAA;AACH,CAAC;AAED,aAAa,CAAC,aAAa,GAAG;IAC5B;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;KACf;IACD;QACE,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,aAAa;QACpB,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE;YACR,OAAO,EAAE;gBACP;oBACE,OAAO,EAAE,YAAY;oBACrB,KAAK,EAAE,MAAM;iBACd;gBACD;oBACE,OAAO,EAAE,MAAM;oBACf,KAAK,EAAE,MAAM;iBACd;aACF;SACF;KACF;CACF,CAAA;AAED,aAAa,CAAC,IAAI,GAAG,iCAAiC,CAAA;AAEtD,4BAAY,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAA","sourcesContent":["import mqtt from 'async-mqtt'\n\nimport { TaskRegistry } from '../task-registry'\nimport { ConnectionManager } from '../connection-manager'\nimport { sleep } from '@things-factory/utils'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\n\nfunction convertDataFormat(data, format) {\n if (format == 'json') {\n return JSON.parse(data)\n } else {\n return data.toString()\n }\n}\n\nasync function MqttSubscribe(step: InputStep, context: Context) {\n const {\n connection: connectionName,\n params: { topic, dataFormat },\n name\n } = step\n\n const { domain, logger, closures, __mqtt_subscriber } = context\n if (!__mqtt_subscriber) {\n context.__mqtt_subscriber = {}\n }\n\n const {\n connection: {\n endpoint: uri,\n params: { user, password }\n }\n } = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n if (!topic) {\n throw Error(`topic is not found for ${connectionName}`)\n }\n\n /*\n * 1. subscriber list에서 subscriber를 찾는다. 없으면, 생성한다.\n * 2. client.once(...)로 메시지를 취한다.\n *\n * TODO 동일 브로커의 다중 subscribe 태스크에 대해서 완벽한 지원을 해야한다.\n * - 현재는 여러 태스크가 동일 topic을 subscribe 하는 경우에 정상동작하지 않을 것이다.\n */\n if (!context.__mqtt_subscriber[name]) {\n try {\n var broker = null\n if (user && password) {\n broker = await mqtt.connectAsync(uri, { username: user, password: password })\n } else {\n broker = await mqtt.connectAsync(uri)\n }\n\n logger.info(`mqtt-connector connection(${connectionName}:${uri}) is connected`)\n\n await broker.subscribe(topic)\n logger.info(`success subscribing topic '${topic}'`)\n\n var TOPIC\n var MESSAGE\n\n context.__mqtt_subscriber[name] = async () => {\n while (!MESSAGE) {\n await sleep(100)\n }\n\n var topic = TOPIC\n var message = MESSAGE\n\n TOPIC = null\n MESSAGE = null\n\n return {\n topic,\n message\n }\n }\n\n broker.on('message', async (messageTopic, message) => {\n if (topic !== messageTopic) {\n return\n }\n\n TOPIC = topic\n MESSAGE = convertDataFormat(message, dataFormat)\n\n // logger.info(`mqtt-subscribe :\\n'${message.toString()}'`)\n })\n\n closures.push(async () => {\n try {\n broker && (await broker.end())\n logger.info(`mqtt-connector connection(${connectionName}:${uri}) is disconnected`)\n } catch (e) {\n logger.error(e)\n }\n })\n } catch (e) {\n logger.error(e)\n }\n }\n\n var { message } = await context.__mqtt_subscriber[name]()\n\n return {\n data: message\n }\n}\n\nMqttSubscribe.parameterSpec = [\n {\n type: 'string',\n name: 'topic',\n label: 'topic'\n },\n {\n type: 'select',\n label: 'data-format',\n name: 'dataFormat',\n property: {\n options: [\n {\n display: 'Plain Text',\n value: 'text'\n },\n {\n display: 'JSON',\n value: 'json'\n }\n ]\n }\n }\n]\n\nMqttSubscribe.help = 'integration/task/mqtt-subscribe'\n\nTaskRegistry.registerTaskHandler('mqtt-subscribe', MqttSubscribe)\n"]}
1
+ {"version":3,"file":"mqtt-subscribe.js","sourceRoot":"","sources":["../../../server/engine/task/mqtt-subscribe.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmFG;;AAEH,0DAAkD;AAClD,oEAA4D;AAI5D,SAAS,iBAAiB,CAAC,IAAI,EAAE,MAAM;IACrC,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;YAC7C,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAA;QACxB,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAA;IACxB,CAAC;AACH,CAAC;AASD,KAAK,UAAU,aAAa,CAAC,IAAe,EAAE,OAAoB;IAChE,MAAM,EACJ,UAAU,EAAE,cAAc,EAC1B,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,EAAE,EACtC,IAAI,EAAE,QAAQ,EACf,GAAG,IAAI,CAAA;IAER,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;IAC5C,MAAM,EAAE,MAAM,EAAE,GAAG,yCAAiB,CAAC,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACxF,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,cAAc,EAAE,CAAC,CAAA;IACvE,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,cAAc,EAAE,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AY,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAA","sourcesContent":["/**\n * MQTT Subscribe Task\n * ====================\n *\n * Pull-Based Message Consumption on MQTT:\n * ---------------------------------------\n * While MQTT is inherently a push-based protocol, this task implements a controlled,\n * pull-style message consumption model. A message is only processed when the task is\n * explicitly invoked (i.e., the consumer actively pulls one message at a time).\n * This enables fine-grained control over message flow and avoids unintended buffering.\n *\n * Overview:\n * ---------\n * This task connects to a specified MQTT broker and subscribes to a given topic.\n * It waits for a single message to arrive, resolves the result, and then removes\n * its internal message handler. It is designed to be reentrant — each execution\n * of this task handles exactly one message.\n *\n * This model is useful for applications where message processing must happen\n * sequentially or be synchronized with external state (e.g., workflows or state machines).\n *\n * Key Features:\n * -------------\n * - One-message-per-invocation: each task call resolves with a single message.\n * - Stateless message flow: the system does not queue or buffer messages locally.\n * - Supports automatic re-subscription on reconnect, improving robustness in unstable networks.\n * - Uses broker-level guarantees (QoS, retain) for durability and delivery control.\n * - Supports multiple data formats (JSON, plain text) and adjustable QoS levels.\n *\n * MQTT Reconnection Handling:\n * ---------------------------\n * The task listens for 'connect' events on the MQTT client. When the client reconnects\n * (e.g., after a dropped network), it automatically re-subscribes to all previously\n * tracked topics. This ensures consistent behavior even in long-running systems or\n * unstable network environments.\n *\n * If a disconnect occurs while a task is waiting for a message, the Promise remains\n * pending until a message is received after reconnection, or until manually cleaned up\n * via the task closure mechanism.\n *\n * How It Works:\n * -------------\n * 1. Retrieve an MQTT client using a named connection.\n * 2. Subscribe to the specified topic (only once per topic per workflow).\n * 3. Register a one-time message handler for the topic.\n * 4. When a message is received:\n * - It is parsed into the requested data format.\n * - The task resolves with the parsed message.\n * - The handler is immediately removed.\n * 5. Re-subscribe to all topics upon reconnect.\n * 6. Clean up all resources (subscription, handler, resolver) on task termination.\n *\n * Assumptions:\n * ------------\n * - Broker reliability is enforced via QoS ≥ 1 and/or retained messages.\n * - Message loss may occur if a message arrives before re-invocation, unless the broker retains it.\n * - The task caller is responsible for repeated invocations to consume additional messages.\n * - MQTT clients are externally managed and assumed to reconnect automatically.\n *\n * Parameters:\n * -----------\n * - topic (string): MQTT topic to subscribe to.\n * - dataFormat ('json' | 'text'): Describes how to parse the incoming message payload.\n * - qos (0 | 1 | 2): Quality of Service level for the subscription (default: 1).\n *\n * Returns:\n * --------\n * - A Promise that resolves with the first received message:\n * { data: any }\n * - If the task is terminated before receiving a message:\n * { data: null, terminated: true }\n *\n * Example:\n * --------\n * await MqttSubscribe({\n * connection: 'my-mqtt',\n * params: {\n * topic: 'sensor/temperature',\n * dataFormat: 'json',\n * qos: 1\n * },\n * name: 'readTemperature'\n * }, context)\n */\n\nimport { TaskRegistry } from '../task-registry.js'\nimport { ConnectionManager } from '../connection-manager.js'\nimport { InputStep } from '../../service/step/step-type.js'\nimport { Context } from '../types.js'\n\nfunction convertDataFormat(data, format) {\n if (format === 'json') {\n try {\n return JSON.parse(data)\n } catch (e) {\n console.error('JSON parse error:', e.message)\n return data.toString()\n }\n } else {\n return data.toString()\n }\n}\n\ninterface MqttContext extends Context {\n __mqtt_handlers?: Map<string, () => void>\n __mqtt_resolvers?: Map<string, (result: any) => void>\n __mqtt_subscriptions?: Set<string>\n __mqtt_event_hooked?: boolean\n}\n\nasync function MqttSubscribe(step: InputStep, context: MqttContext) {\n const {\n connection: connectionName,\n params: { topic, dataFormat, qos = 1 },\n name: stepName\n } = step\n\n const { domain, logger, closures } = context\n const { client } = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n if (!client) throw new Error(`connection not found: ${connectionName}`)\n if (!topic) throw new Error(`Missing topic for connection: ${connectionName}`)\n\n const subscriberId = `${domain}_${connectionName}_${topic}_${stepName}`\n\n context.__mqtt_subscriptions ??= new Set()\n context.__mqtt_resolvers ??= new Map()\n context.__mqtt_handlers ??= new Map()\n\n // Setup MQTT client reconnect/resubscribe handlers only once\n if (!context.__mqtt_event_hooked) {\n client.on('connect', async () => {\n logger.info('[MQTT] Reconnected. Resubscribing to topics...')\n for (const t of context.__mqtt_subscriptions) {\n try {\n await client.subscribe(t, { qos })\n logger.info(`[MQTT] Resubscribed to topic: ${t}`)\n } catch (e) {\n logger.error(`[MQTT] Failed to resubscribe to topic ${t}: ${e.message}`)\n }\n }\n })\n\n client.on('offline', () => {\n logger.warn('[MQTT] Client offline')\n })\n\n client.on('close', () => {\n logger.warn('[MQTT] Connection closed')\n })\n\n client.on('error', err => {\n logger.error(`[MQTT] Error: ${err.message}`)\n })\n\n context.__mqtt_event_hooked = true\n }\n\n // Subscribe if not already done\n if (!context.__mqtt_subscriptions.has(topic)) {\n await client.subscribe(topic, { qos: Number(qos) })\n context.__mqtt_subscriptions.add(topic)\n logger.info(`Subscribed to topic: ${topic} (QoS: ${qos})`)\n }\n\n // Remove previous handler for this step\n if (context.__mqtt_handlers.has(subscriberId)) {\n const removeHandler = context.__mqtt_handlers.get(subscriberId)\n removeHandler?.()\n context.__mqtt_handlers.delete(subscriberId)\n }\n\n return new Promise(resolve => {\n context.__mqtt_resolvers.set(subscriberId, resolve)\n\n const messageHandler = (messageTopic, message) => {\n if (messageTopic !== topic) return\n\n const converted = convertDataFormat(message, dataFormat)\n const resolver = context.__mqtt_resolvers.get(subscriberId)\n\n if (resolver) {\n context.__mqtt_resolvers.delete(subscriberId)\n resolver({ data: converted })\n client.removeListener('message', messageHandler)\n context.__mqtt_handlers.delete(subscriberId)\n }\n }\n\n client.on('message', messageHandler)\n context.__mqtt_handlers.set(subscriberId, () => {\n client.removeListener('message', messageHandler)\n })\n\n closures.push(async () => {\n try {\n if (context.__mqtt_subscriptions?.has(topic)) {\n await client.unsubscribe(topic)\n context.__mqtt_subscriptions.delete(topic)\n logger.info(`Unsubscribed from topic: ${topic}`)\n }\n\n if (context.__mqtt_handlers?.has(subscriberId)) {\n const remove = context.__mqtt_handlers.get(subscriberId)\n remove?.()\n context.__mqtt_handlers.delete(subscriberId)\n }\n\n if (context.__mqtt_resolvers?.has(subscriberId)) {\n const resolver = context.__mqtt_resolvers.get(subscriberId)\n resolver?.({ data: null, terminated: true })\n context.__mqtt_resolvers.delete(subscriberId)\n }\n } catch (e) {\n logger.error(`MQTT cleanup error: ${e.message}`)\n }\n })\n\n logger.info(`Waiting for MQTT message on topic: ${topic}`)\n })\n}\n\n// Task parameter definitions for UI or DSL support\nMqttSubscribe.parameterSpec = [\n {\n type: 'string',\n name: 'topic',\n label: 'topic'\n },\n {\n type: 'select',\n label: 'data-format',\n name: 'dataFormat',\n property: {\n options: [\n { display: '', value: undefined },\n { display: 'Plain Text', value: 'text' },\n { display: 'JSON', value: 'json' }\n ]\n }\n },\n {\n type: 'select',\n label: 'QoS',\n name: 'qos',\n property: {\n options: [\n { display: '', value: undefined },\n { display: '0 (at most once)', value: 0 },\n { display: '1 (at least once)', value: 1 },\n { display: '2 (exactly once)', value: 2 }\n ]\n }\n }\n]\n\nMqttSubscribe.help = 'integration/task/mqtt-subscribe'\n\n// Register task with runtime registry\nTaskRegistry.registerTaskHandler('mqtt-subscribe', MqttSubscribe)\n"]}
@@ -69,7 +69,7 @@ async function MssqlProcedure(step, context) {
69
69
  : String(calculated);
70
70
  }
71
71
  if ((dir == DIR.In || dir == DIR.Inout) && maxSize > 0 && type == 'String') {
72
- sum[name].type = mssql === null || mssql === void 0 ? void 0 : mssql.VarChar(maxSize);
72
+ sum[name].type = mssql?.VarChar(maxSize);
73
73
  sum[name].maxSize = maxSize;
74
74
  }
75
75
  return sum;
@@ -1 +1 @@
1
- {"version":3,"file":"mssql-procedure.js","sourceRoot":"","sources":["../../../server/engine/task/mssql-procedure.ts"],"names":[],"mappings":";;AAAA,6CAA4C;AAC5C,iDAA8C;AAC9C,8DAAyD;AACzD,oDAA+C;AAG/C,eAAY;AAEZ,IAAI,CAAC;IACH,IAAI,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAC9B,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,YAAM,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,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AAA;YAC7B,CAAC;YAED,OAAO,GAAG,CAAA;QACZ,CAAC,EAAE,EAAE,CAAC,CAAA;IAER,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAA;IAEzE,OAAO;QACL,IAAI,EAAE,MAAM;KACb,CAAA;AACH,CAAC;AAED,cAAc,CAAC,aAAa,GAAG;IAC7B;QACE,IAAI,EAAE,sBAAsB;QAC5B,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE;YACR,MAAM,EAAE,OAAO;SAChB;KACF;CACF,CAAA;AAED,cAAc,CAAC,IAAI,GAAG,kCAAkC,CAAA;AAExD,4BAAY,CAAC,mBAAmB,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAA","sourcesContent":["import { logger } from '@things-factory/env'\nimport { access } from '@things-factory/utils'\nimport { ConnectionManager } from '../connection-manager'\nimport { TaskRegistry } from '../task-registry'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\nimport 'ses'\n\ntry {\n var mssql = require('mssql')\n} catch (err) {\n logger.error('mssql module loading failed', err)\n}\n\ntype ProcedureParameterType = {\n name: string\n dir: string\n type: string\n val?: any\n accessor?: string\n maxSize?: number\n}\n\ntype ValueType = {\n code?: string\n procedure?: string\n parameters?: ProcedureParameterType[]\n}\n\nconst DIR = {\n In: 'in',\n Out: 'out',\n Inout: 'inout' /* 초기값이 있는 out 파라미터 */\n}\n\nconst NUMBER_TYPES = [\n 'TINYINT',\n 'SMALLINT',\n 'INT',\n 'BIGINT',\n 'FLOAT',\n 'READ',\n 'DECIMAL',\n 'NUMERIC',\n 'MONEY',\n 'SMALLMONEY'\n]\n\nconst DATE_TYPES = ['DATE', 'TIME', 'DATETIME', 'SMALLDATETIME', 'DATETIME2']\nconst PARAMETERIZED_STRINGS = ['NCHAR', 'NVARCHAR', 'NTEXT', 'DECIMAL', 'NUMERIC']\n\nasync function MssqlProcedure(step: InputStep, context: Context) {\n var { domain, user, data, variables, lng } = context\n var { connection: connectionName, params } = step\n\n var { code = '', procedure = '', parameters = [] } = params.parameters as ValueType\n\n var dbconnection = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n if (!code) {\n throw 'procedure code not defined'\n }\n\n const compartment = new Compartment({\n domain,\n user,\n lng,\n data,\n variables,\n console\n })\n\n let evalCode\n try {\n evalCode = compartment.evaluate('`' + code + '`')\n } catch (err) {\n throw new Error(`Failed to evaluate code: ${err.message}`)\n }\n\n code = evalCode\n\n const procedureParameters =\n parameters &&\n parameters.reduce((sum, { name, val, dir, type, accessor, maxSize }) => {\n sum[name] = {\n dir: DIR[dir],\n type\n }\n\n const calculated = accessor ? access(accessor, data) || val : val\n\n if (calculated !== undefined) {\n sum[name].val = NUMBER_TYPES.includes(type)\n ? Number(calculated)\n : DATE_TYPES.includes(type)\n ? new Date(calculated)\n : String(calculated)\n }\n\n if ((dir == DIR.In || dir == DIR.Inout) && maxSize > 0 && type == 'String') {\n sum[name].type = mssql?.VarChar(maxSize)\n sum[name].maxSize = maxSize\n }\n\n return sum\n }, {})\n\n const result = await dbconnection.execute(procedure, procedureParameters)\n\n return {\n data: result\n }\n}\n\nMssqlProcedure.parameterSpec = [\n {\n type: 'procedure-parameters',\n name: 'parameters',\n label: '',\n property: {\n dbtype: 'mssql'\n }\n }\n]\n\nMssqlProcedure.help = 'integration/task/mssql-procedure'\n\nTaskRegistry.registerTaskHandler('mssql-procedure', MssqlProcedure)\n"]}
1
+ {"version":3,"file":"mssql-procedure.js","sourceRoot":"","sources":["../../../server/engine/task/mssql-procedure.ts"],"names":[],"mappings":";;AAAA,6CAA4C;AAC5C,iDAA8C;AAC9C,8DAAyD;AACzD,oDAA+C;AAG/C,eAAY;AAEZ,IAAI,CAAC;IACH,IAAI,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAC9B,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,YAAM,CAAC,KAAK,CAAC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,CAAA;YAC7B,CAAC;YAED,OAAO,GAAG,CAAA;QACZ,CAAC,EAAE,EAAE,CAAC,CAAA;IAER,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAA;IAEzE,OAAO;QACL,IAAI,EAAE,MAAM;KACb,CAAA;AACH,CAAC;AAED,cAAc,CAAC,aAAa,GAAG;IAC7B;QACE,IAAI,EAAE,sBAAsB;QAC5B,IAAI,EAAE,YAAY;QAClB,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE;YACR,MAAM,EAAE,OAAO;SAChB;KACF;CACF,CAAA;AAED,cAAc,CAAC,IAAI,GAAG,kCAAkC,CAAA;AAExD,4BAAY,CAAC,mBAAmB,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAA","sourcesContent":["import { logger } from '@things-factory/env'\nimport { access } from '@things-factory/utils'\nimport { ConnectionManager } from '../connection-manager'\nimport { TaskRegistry } from '../task-registry'\nimport { InputStep } from '../../service/step/step-type'\nimport { Context } from '../types'\nimport 'ses'\n\ntry {\n var mssql = require('mssql')\n} catch (err) {\n logger.error('mssql module loading failed', err)\n}\n\ntype ProcedureParameterType = {\n name: string\n dir: string\n type: string\n val?: any\n accessor?: string\n maxSize?: number\n}\n\ntype ValueType = {\n code?: string\n procedure?: string\n parameters?: ProcedureParameterType[]\n}\n\nconst DIR = {\n In: 'in',\n Out: 'out',\n Inout: 'inout' /* 초기값이 있는 out 파라미터 */\n}\n\nconst NUMBER_TYPES = [\n 'TINYINT',\n 'SMALLINT',\n 'INT',\n 'BIGINT',\n 'FLOAT',\n 'READ',\n 'DECIMAL',\n 'NUMERIC',\n 'MONEY',\n 'SMALLMONEY'\n]\n\nconst DATE_TYPES = ['DATE', 'TIME', 'DATETIME', 'SMALLDATETIME', 'DATETIME2']\nconst PARAMETERIZED_STRINGS = ['NCHAR', 'NVARCHAR', 'NTEXT', 'DECIMAL', 'NUMERIC']\n\nasync function MssqlProcedure(step: InputStep, context: Context) {\n var { domain, user, data, variables, lng } = context\n var { connection: connectionName, params } = step\n\n var { code = '', procedure = '', parameters = [] } = params.parameters as ValueType\n\n var dbconnection = ConnectionManager.getConnectionInstanceByName(domain, connectionName)\n\n if (!code) {\n throw 'procedure code not defined'\n }\n\n const compartment = new Compartment({\n domain,\n user,\n lng,\n data,\n variables,\n console\n })\n\n let evalCode\n try {\n evalCode = compartment.evaluate('`' + code + '`')\n } catch (err) {\n throw new Error(`Failed to evaluate code: ${err.message}`)\n }\n\n code = evalCode\n\n const procedureParameters =\n parameters &&\n parameters.reduce((sum, { name, val, dir, type, accessor, maxSize }) => {\n sum[name] = {\n dir: DIR[dir],\n type\n }\n\n const calculated = accessor ? access(accessor, data) || val : val\n\n if (calculated !== undefined) {\n sum[name].val = NUMBER_TYPES.includes(type)\n ? Number(calculated)\n : DATE_TYPES.includes(type)\n ? new Date(calculated)\n : String(calculated)\n }\n\n if ((dir == DIR.In || dir == DIR.Inout) && maxSize > 0 && type == 'String') {\n sum[name].type = mssql?.VarChar(maxSize)\n sum[name].maxSize = maxSize\n }\n\n return sum\n }, {})\n\n const result = await dbconnection.execute(procedure, procedureParameters)\n\n return {\n data: result\n }\n}\n\nMssqlProcedure.parameterSpec = [\n {\n type: 'procedure-parameters',\n name: 'parameters',\n label: '',\n property: {\n dbtype: 'mssql'\n }\n }\n]\n\nMssqlProcedure.help = 'integration/task/mssql-procedure'\n\nTaskRegistry.registerTaskHandler('mssql-procedure', MssqlProcedure)\n"]}
@@ -12,18 +12,18 @@ catch (err) {
12
12
  env_1.logger.error('oracledb module loading failed', err);
13
13
  }
14
14
  const TYPES = {
15
- Number: oracledb === null || oracledb === void 0 ? void 0 : oracledb.NUMBER,
16
- String: oracledb === null || oracledb === void 0 ? void 0 : oracledb.STRING,
17
- Date: oracledb === null || oracledb === void 0 ? void 0 : oracledb.DATE,
18
- Buffer: oracledb === null || oracledb === void 0 ? void 0 : oracledb.BUFFER,
19
- Blob: oracledb === null || oracledb === void 0 ? void 0 : oracledb.BLOB,
20
- Clob: oracledb === null || oracledb === void 0 ? void 0 : oracledb.CLOB,
21
- Cursor: oracledb === null || oracledb === void 0 ? void 0 : oracledb.CURSOR
15
+ Number: oracledb?.NUMBER,
16
+ String: oracledb?.STRING,
17
+ Date: oracledb?.DATE,
18
+ Buffer: oracledb?.BUFFER,
19
+ Blob: oracledb?.BLOB,
20
+ Clob: oracledb?.CLOB,
21
+ Cursor: oracledb?.CURSOR
22
22
  };
23
23
  const DIR = {
24
- In: oracledb === null || oracledb === void 0 ? void 0 : oracledb.BIND_IN,
25
- Inout: oracledb === null || oracledb === void 0 ? void 0 : oracledb.BIND_INOUT,
26
- Out: oracledb === null || oracledb === void 0 ? void 0 : oracledb.BIND_OUT
24
+ In: oracledb?.BIND_IN,
25
+ Inout: oracledb?.BIND_INOUT,
26
+ Out: oracledb?.BIND_OUT
27
27
  };
28
28
  async function OracleProcedure(step, context) {
29
29
  var { domain, user, data, variables, lng } = context;