@kineticdata/react 5.1.2 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/assets/task/icons/drag-handle.svg +3 -0
  2. package/assets/task/icons/plus_small.svg +2 -4
  3. package/lib/apis/agent/adapters.js +16 -12
  4. package/lib/apis/agent/bridges.js +54 -41
  5. package/lib/apis/agent/handlers.js +51 -38
  6. package/lib/apis/core/activity.js +19 -11
  7. package/lib/apis/core/attributeDefinitions.js +54 -46
  8. package/lib/apis/core/attributeDefinitions.test.js +47 -55
  9. package/lib/apis/core/authentication.js +58 -63
  10. package/lib/apis/core/backgroundJobs.js +38 -30
  11. package/lib/apis/core/bridgeModelAttributeMappings.js +42 -34
  12. package/lib/apis/core/bridgeModelAttributes.js +47 -37
  13. package/lib/apis/core/bridgeModelMappings.js +42 -34
  14. package/lib/apis/core/bridgeModelQualificationMappings.js +42 -34
  15. package/lib/apis/core/bridgeModelQualifications.js +42 -34
  16. package/lib/apis/core/bridgeModels.js +56 -46
  17. package/lib/apis/core/bridgeModels.test.js +64 -80
  18. package/lib/apis/core/bridgedresources.js +64 -72
  19. package/lib/apis/core/bridgedresources.test.js +33 -30
  20. package/lib/apis/core/categories.js +59 -52
  21. package/lib/apis/core/categories.test.js +36 -33
  22. package/lib/apis/core/fileResources.js +41 -33
  23. package/lib/apis/core/filestores.js +42 -34
  24. package/lib/apis/core/formTypes.js +50 -44
  25. package/lib/apis/core/forms.js +53 -49
  26. package/lib/apis/core/forms.test.js +60 -74
  27. package/lib/apis/core/kapps.js +45 -39
  28. package/lib/apis/core/kapps.test.js +45 -52
  29. package/lib/apis/core/logs.js +20 -16
  30. package/lib/apis/core/memberships.js +23 -20
  31. package/lib/apis/core/meta.js +31 -19
  32. package/lib/apis/core/notices.js +17 -9
  33. package/lib/apis/core/oauthClients.js +49 -45
  34. package/lib/apis/core/platformComponents.js +73 -57
  35. package/lib/apis/core/platformItems.js +22 -13
  36. package/lib/apis/core/profile.js +28 -21
  37. package/lib/apis/core/profile.test.js +20 -17
  38. package/lib/apis/core/securityPolicyDefinitions.js +48 -41
  39. package/lib/apis/core/securityPolicyDefinitions.test.js +50 -60
  40. package/lib/apis/core/space.js +23 -16
  41. package/lib/apis/core/space.test.js +31 -38
  42. package/lib/apis/core/submissions.js +213 -186
  43. package/lib/apis/core/submissions.test.js +39 -36
  44. package/lib/apis/core/teams.js +51 -44
  45. package/lib/apis/core/teams.test.js +42 -39
  46. package/lib/apis/core/translations.js +123 -130
  47. package/lib/apis/core/translations.test.js +278 -368
  48. package/lib/apis/core/users.js +56 -49
  49. package/lib/apis/core/users.test.js +42 -39
  50. package/lib/apis/core/version.js +20 -11
  51. package/lib/apis/core/webApis.js +42 -34
  52. package/lib/apis/core/webhooks.js +48 -41
  53. package/lib/apis/core/webhooks.test.js +50 -60
  54. package/lib/apis/core/webhooksJobs.js +30 -26
  55. package/lib/apis/core/workflows.js +52 -44
  56. package/lib/apis/http.js +121 -80
  57. package/lib/apis/http.test.js +137 -38
  58. package/lib/apis/index.js +506 -50
  59. package/lib/apis/system/index.js +363 -215
  60. package/lib/apis/task/index.js +294 -227
  61. package/lib/components/agent/bridge/BridgeForm.js +50 -50
  62. package/lib/components/agent/bridge/BridgeTable.js +16 -9
  63. package/lib/components/agent/filestore/FilestoreForm.js +49 -48
  64. package/lib/components/agent/filestore/FilestoreTable.js +16 -9
  65. package/lib/components/agent/handler/AgentHandlerForm.js +24 -27
  66. package/lib/components/agent/handler/AgentHandlerTable.js +17 -10
  67. package/lib/components/common/AttributeSelect.js +15 -9
  68. package/lib/components/common/BridgeSelect.js +48 -43
  69. package/lib/components/common/ComponentConfigContext.js +9 -2
  70. package/lib/components/common/ContentEditable.js +36 -60
  71. package/lib/components/common/FormSelect.js +70 -58
  72. package/lib/components/common/NodeSelect.js +23 -19
  73. package/lib/components/common/Scroller.js +24 -23
  74. package/lib/components/common/StaticSelect.js +57 -50
  75. package/lib/components/common/TableInput.js +54 -57
  76. package/lib/components/common/TeamSelect.js +42 -39
  77. package/lib/components/common/ToastContainer.js +170 -0
  78. package/lib/components/common/Typeahead.js +121 -138
  79. package/lib/components/common/UserSelect.js +42 -41
  80. package/lib/components/common/authentication/AuthInterceptor.js +15 -19
  81. package/lib/components/common/authentication/AuthInterceptor.test.js +46 -64
  82. package/lib/components/common/authentication/AuthenticationContainer.js +350 -454
  83. package/lib/components/common/authentication/RequestInterceptor.js +16 -19
  84. package/lib/components/common/code_input/CodeInput.js +92 -122
  85. package/lib/components/common/code_input/draftHelpers.js +96 -90
  86. package/lib/components/common/code_input/languageHelpers.js +49 -47
  87. package/lib/components/common/code_input/languageHelpers.test.js +21 -16
  88. package/lib/components/common/defaults/Toast.js +26 -0
  89. package/lib/components/common/defaults/index.js +13 -0
  90. package/lib/components/core/CoreFormModal.js +26 -24
  91. package/lib/components/core/CoreModal.js +37 -31
  92. package/lib/components/core/attribute_definition/AttributeDefinitionForm.js +24 -23
  93. package/lib/components/core/attribute_definition/AttributeDefinitionTable.js +25 -18
  94. package/lib/components/core/bridge_model/BridgeModelForm.js +27 -37
  95. package/lib/components/core/bridge_model/BridgeModelTable.js +17 -10
  96. package/lib/components/core/bridge_model_attribute/BridgeModelAttributeForm.js +17 -16
  97. package/lib/components/core/bridge_model_attribute/BridgeModelAttributeTable.js +25 -21
  98. package/lib/components/core/bridge_model_qualification/BridgeModelQualificationForm.js +20 -20
  99. package/lib/components/core/bridge_model_qualification/BridgeModelQualificationTable.js +27 -22
  100. package/lib/components/core/category/CategoryForm.js +22 -22
  101. package/lib/components/core/category/CategoryTable.js +28 -16
  102. package/lib/components/core/core_form/CoreForm.js +209 -285
  103. package/lib/components/core/core_form/CoreForm.test.js +12 -10
  104. package/lib/components/core/core_form/defaults/index.js +52 -44
  105. package/lib/components/core/core_form/globals.js +14 -5
  106. package/lib/components/core/field_definition/FieldDefinitionForm.js +23 -21
  107. package/lib/components/core/field_definition/FieldDefinitionTable.js +26 -15
  108. package/lib/components/core/file_resource/FileResourceForm.js +38 -37
  109. package/lib/components/core/file_resource/FileResourceTable.js +16 -12
  110. package/lib/components/core/form/FormForm.js +56 -61
  111. package/lib/components/core/form/FormTable.js +47 -33
  112. package/lib/components/core/form_type/FormTypeForm.js +14 -13
  113. package/lib/components/core/form_type/FormTypeTable.js +15 -9
  114. package/lib/components/core/i18n/I18n.js +54 -61
  115. package/lib/components/core/i18n/I18nContext.js +9 -2
  116. package/lib/components/core/i18n/I18nProvider.js +40 -43
  117. package/lib/components/core/i18n/Moment.js +40 -50
  118. package/lib/components/core/index_definition/IndexDefinitionForm.js +23 -24
  119. package/lib/components/core/index_definition/IndexDefinitionTable.js +31 -16
  120. package/lib/components/core/index_job/IndexJobTable.js +20 -15
  121. package/lib/components/core/kapp/KappForm.js +57 -58
  122. package/lib/components/core/kapp/KappTable.js +34 -44
  123. package/lib/components/core/log/LogTable.js +42 -34
  124. package/lib/components/core/oauth_client/OAuthClientForm.js +17 -17
  125. package/lib/components/core/oauth_client/OAuthClientTable.js +12 -8
  126. package/lib/components/core/platform_component/AgentComponentForm.js +15 -15
  127. package/lib/components/core/platform_component/AgentComponentTable.js +10 -5
  128. package/lib/components/core/platform_component/TaskComponentForm.js +14 -14
  129. package/lib/components/core/profile/ProfileForm.js +40 -39
  130. package/lib/components/core/security_definition/SecurityDefinitionForm.js +28 -25
  131. package/lib/components/core/security_definition/SecurityDefinitionTable.js +27 -17
  132. package/lib/components/core/space/SpaceForm.js +79 -90
  133. package/lib/components/core/submission/DatastoreSubmissionFilters.js +39 -40
  134. package/lib/components/core/submission/DatastoreSubmissionTable.js +37 -34
  135. package/lib/components/core/submission/FormSubmissionFilters.js +79 -75
  136. package/lib/components/core/submission/FormSubmissionTable.js +64 -39
  137. package/lib/components/core/submission/KappSubmissionTable.js +67 -48
  138. package/lib/components/core/submission/SubmissionForm.js +126 -55
  139. package/lib/components/core/submission/SubmissionTable.js +24 -20
  140. package/lib/components/core/submission/helpers.js +37 -33
  141. package/lib/components/core/submission/helpers.test.js +69 -20
  142. package/lib/components/core/team/TeamForm.js +24 -21
  143. package/lib/components/core/team/TeamTable.js +27 -16
  144. package/lib/components/core/translation/ContextForm.js +13 -10
  145. package/lib/components/core/translation/ContextTable.js +13 -10
  146. package/lib/components/core/translation/EntryForm.js +27 -24
  147. package/lib/components/core/translation/EntryTable.js +19 -16
  148. package/lib/components/core/translation/LocaleForm.js +16 -13
  149. package/lib/components/core/translation/LocaleTable.js +12 -8
  150. package/lib/components/core/user/UserForm.js +38 -37
  151. package/lib/components/core/user/UserTable.js +42 -20
  152. package/lib/components/core/webapi/WebApiForm.js +87 -80
  153. package/lib/components/core/webapi/WebApiTable.js +28 -17
  154. package/lib/components/core/webhook/WebhookForm.js +33 -32
  155. package/lib/components/core/webhook/WebhookTable.js +41 -29
  156. package/lib/components/core/webhook_job/WebhookJobTable.js +58 -35
  157. package/lib/components/form/Form.helpers.js +182 -108
  158. package/lib/components/form/Form.js +467 -524
  159. package/lib/components/form/Form.models.js +39 -24
  160. package/lib/components/form/FormState.js +8 -5
  161. package/lib/components/form/KitchenSinkForm.js +135 -4
  162. package/lib/components/form/defaults/AttributesField.js +48 -59
  163. package/lib/components/form/defaults/CheckboxField.js +14 -6
  164. package/lib/components/form/defaults/CodeField.js +15 -7
  165. package/lib/components/form/defaults/FormButtons.js +12 -4
  166. package/lib/components/form/defaults/FormError.js +12 -4
  167. package/lib/components/form/defaults/FormField.js +15 -7
  168. package/lib/components/form/defaults/FormLayout.js +12 -4
  169. package/lib/components/form/defaults/FormMultiField.js +15 -7
  170. package/lib/components/form/defaults/PasswordField.js +14 -6
  171. package/lib/components/form/defaults/RadioField.js +15 -7
  172. package/lib/components/form/defaults/SampleTeamsRolesFIeld.js +17 -9
  173. package/lib/components/form/defaults/SelectField.js +16 -8
  174. package/lib/components/form/defaults/SelectMultiField.js +15 -7
  175. package/lib/components/form/defaults/TableField.js +14 -6
  176. package/lib/components/form/defaults/TeamField.js +15 -7
  177. package/lib/components/form/defaults/TeamMultiField.js +15 -7
  178. package/lib/components/form/defaults/TextField.js +14 -6
  179. package/lib/components/form/defaults/TextMultiField.js +26 -28
  180. package/lib/components/form/defaults/UserField.js +15 -7
  181. package/lib/components/form/defaults/UserMultiField.js +15 -7
  182. package/lib/components/form/defaults/index.js +48 -41
  183. package/lib/components/form/tests/Form.test.js +568 -864
  184. package/lib/components/form/tests/components.js +15 -25
  185. package/lib/components/form/tests/helpers.test.js +35 -33
  186. package/lib/components/index.js +1034 -135
  187. package/lib/components/system/SystemBackgroundTasksTable.js +14 -10
  188. package/lib/components/system/SystemCassandraForm.js +98 -0
  189. package/lib/components/system/SystemElasticSearchForm.js +98 -0
  190. package/lib/components/system/SystemFilestoreForm.js +36 -28
  191. package/lib/components/system/SystemForm.js +19 -16
  192. package/lib/components/system/SystemIngressForm.js +85 -36
  193. package/lib/components/system/SystemSecurityForm.js +17 -14
  194. package/lib/components/system/SystemSmtpForm.js +13 -13
  195. package/lib/components/system/SystemTaskAdapterForm.js +49 -21
  196. package/lib/components/system/SystemTrustedCertificateForm.js +40 -0
  197. package/lib/components/system/SystemTrustedCertificatesTable.js +74 -0
  198. package/lib/components/system/SystemUserForm.js +15 -14
  199. package/lib/components/system/helpers.js +281 -98
  200. package/lib/components/system/helpers.test.js +16 -12
  201. package/lib/components/system/spaces/SystemSpaceForm.js +25 -24
  202. package/lib/components/system/spaces/SystemTenantForm.js +112 -68
  203. package/lib/components/system/spaces/SystemTenantTable.js +12 -8
  204. package/lib/components/table/Table.js +295 -227
  205. package/lib/components/table/Table.redux.js +339 -355
  206. package/lib/components/table/Table.redux.test.js +49 -47
  207. package/lib/components/table/Table.test.js +146 -132
  208. package/lib/components/table/defaults/BodyCell.js +12 -6
  209. package/lib/components/table/defaults/BodyRow.js +10 -4
  210. package/lib/components/table/defaults/BooleanFilter.js +17 -11
  211. package/lib/components/table/defaults/ColumnControl.js +26 -0
  212. package/lib/components/table/defaults/EmptyBodyRow.js +12 -6
  213. package/lib/components/table/defaults/FilterLayout.js +17 -11
  214. package/lib/components/table/defaults/Footer.js +11 -5
  215. package/lib/components/table/defaults/FooterCell.js +10 -4
  216. package/lib/components/table/defaults/FooterRow.js +10 -4
  217. package/lib/components/table/defaults/Header.js +10 -4
  218. package/lib/components/table/defaults/HeaderCell.js +16 -10
  219. package/lib/components/table/defaults/HeaderRow.js +10 -4
  220. package/lib/components/table/defaults/PaginationControl.js +18 -9
  221. package/lib/components/table/defaults/TableBody.js +10 -4
  222. package/lib/components/table/defaults/TableLayout.js +12 -6
  223. package/lib/components/table/defaults/TextFilter.js +16 -10
  224. package/lib/components/table/defaults/index.js +43 -33
  225. package/lib/components/task/builder/Connector.js +100 -111
  226. package/lib/components/task/builder/ConnectorForm.js +17 -11
  227. package/lib/components/task/builder/Node.js +101 -83
  228. package/lib/components/task/builder/NodeForm.js +30 -27
  229. package/lib/components/task/builder/NodeParametersForm.js +27 -24
  230. package/lib/components/task/builder/SvgCanvas.js +67 -96
  231. package/lib/components/task/builder/SvgText.js +19 -134
  232. package/lib/components/task/builder/TaskDefinitionConfigForm.js +27 -22
  233. package/lib/components/task/builder/TreeBuilder.js +140 -115
  234. package/lib/components/task/builder/builder.redux.js +311 -326
  235. package/lib/components/task/builder/constants.js +94 -45
  236. package/lib/components/task/builder/helpers.js +184 -173
  237. package/lib/components/task/builder/helpers.test.js +20 -18
  238. package/lib/components/task/builder/models.js +121 -98
  239. package/lib/components/task/category/TaskCategoryForm.js +31 -29
  240. package/lib/components/task/category/TaskCategoryTable.js +12 -8
  241. package/lib/components/task/common/UsageTable.js +16 -12
  242. package/lib/components/task/engine/EngineSettingsForm.js +13 -11
  243. package/lib/components/task/errors/RunErrorTable.js +50 -27
  244. package/lib/components/task/errors/SystemErrorsTable.js +13 -9
  245. package/lib/components/task/handlers/HandlerForm.js +55 -55
  246. package/lib/components/task/handlers/HandlerTable.js +35 -19
  247. package/lib/components/task/handlers/MissingHandlerTable.js +12 -8
  248. package/lib/components/task/policy_rule/PolicyRuleForm.js +33 -32
  249. package/lib/components/task/policy_rule/PolicyRuleTable.js +12 -8
  250. package/lib/components/task/runs/CreateManualTriggerForm.js +17 -15
  251. package/lib/components/task/runs/RunTable.js +45 -29
  252. package/lib/components/task/runs/RunTaskTable.js +10 -6
  253. package/lib/components/task/sources/SourceForm.js +47 -47
  254. package/lib/components/task/sources/SourceTable.js +29 -18
  255. package/lib/components/task/triggers/TriggerTable.js +71 -41
  256. package/lib/components/task/workflows/LinkedWorkflowForm.js +48 -54
  257. package/lib/components/task/workflows/LinkedWorkflowTable.js +46 -26
  258. package/lib/components/task/workflows/MissingRoutineTable.js +12 -8
  259. package/lib/components/task/workflows/WorkflowForm.js +49 -44
  260. package/lib/components/task/workflows/WorkflowTable.js +47 -29
  261. package/lib/helpers/SearchBuilder.js +73 -127
  262. package/lib/helpers/SearchBuilder.test.js +184 -175
  263. package/lib/helpers/index.js +116 -74
  264. package/lib/index.js +87 -38
  265. package/lib/reducer.js +11 -3
  266. package/lib/saga.js +42 -38
  267. package/lib/store.js +59 -35
  268. package/package.json +17 -29
  269. package/proxyhelper.js +122 -57
  270. package/assets/discussions/images/avi_128.png +0 -0
  271. package/assets/discussions/images/excel_128.png +0 -0
  272. package/assets/discussions/images/html_128.png +0 -0
  273. package/assets/discussions/images/illustrator_128.png +0 -0
  274. package/assets/discussions/images/indesign_128.png +0 -0
  275. package/assets/discussions/images/movie_128.png +0 -0
  276. package/assets/discussions/images/mpeg_128.png +0 -0
  277. package/assets/discussions/images/pdf_128.png +0 -0
  278. package/assets/discussions/images/photoshop_128.png +0 -0
  279. package/assets/discussions/images/powerpoint_128.png +0 -0
  280. package/assets/discussions/images/txt_128.png +0 -0
  281. package/assets/discussions/images/unknown_128.png +0 -0
  282. package/assets/discussions/images/word_128.png +0 -0
  283. package/assets/discussions/styles/_discussion.scss +0 -506
  284. package/lib/apis/discussions/index.js +0 -395
  285. package/lib/apis/socket/index.js +0 -77
  286. package/lib/apis/socket/socket.js +0 -350
  287. package/lib/apis/socket/socket.test.js +0 -90
  288. package/lib/apis/socket/timer.js +0 -45
  289. package/lib/apis/socket/timer.test.js +0 -51
  290. package/lib/apis/socket/topic.js +0 -185
  291. package/lib/apis/topics/index.js +0 -19
  292. package/lib/components/discussions/ChatInputForm.js +0 -424
  293. package/lib/components/discussions/DateBanner.js +0 -10
  294. package/lib/components/discussions/Discussion.js +0 -202
  295. package/lib/components/discussions/DiscussionForm.js +0 -227
  296. package/lib/components/discussions/InvitationForm.js +0 -107
  297. package/lib/components/discussions/MessageHistory.js +0 -110
  298. package/lib/components/discussions/MessagesByDate.js +0 -40
  299. package/lib/components/discussions/MessagesList.js +0 -30
  300. package/lib/components/discussions/MoreMessagesBanner.js +0 -26
  301. package/lib/components/discussions/ScrollHelper.js +0 -84
  302. package/lib/components/discussions/SystemMessage.js +0 -88
  303. package/lib/components/discussions/SystemMessageGroup.js +0 -15
  304. package/lib/components/discussions/UserMessage.js +0 -163
  305. package/lib/components/discussions/UserMessageGroup.js +0 -34
  306. package/lib/components/discussions/redux.js +0 -178
  307. package/lib/components/discussions/sagas.js +0 -500
  308. package/lib/helpers/discussions/canManage.js +0 -30
  309. package/lib/helpers/discussions/canManage.test.js +0 -69
  310. package/lib/helpers/discussions/generateSystemMessageContent.js +0 -131
  311. package/lib/helpers/discussions/generateSystemMessageContent.test.js +0 -450
  312. package/lib/models/discussions.js +0 -76
  313. package/lib/models/index.js +0 -1
@@ -1,350 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/esm/createClass";
4
- import { Topic, TOPIC_STATUS } from './topic';
5
- import { Timer } from './timer';
6
- export var TOPIC_HUB_TOPIC = 'topichub';
7
- export var TOPIC_HUB_ACTION_IDENTIFY = 'identify';
8
- export var TOPIC_HUB_ACTION_HEARTBEAT = 'heartbeat';
9
- export var TOPIC_HUB_ACTION_SUBSCRIBE = 'subscribe';
10
- export var TOPIC_HUB_ACTION_UNSUBSCRIBE = 'unsubscribe';
11
- export var TOPIC_HUB_EVENT_PRESENCE = 'presence';
12
- export var TOPIC_HUB_EVENT_ACK_OK = 'ack-ok';
13
- export var TOPIC_HUB_EVENT_ACK_ERROR = 'ack-error';
14
- export var TOPIC_HUB_HEARTBEAT_INTERVAL = 30000; // Heartbeat every 30s.
15
-
16
- export var VALID_EVENTS = ['connect', 'identify', 'disconnect', 'status'];
17
- export var PRESENCE_CREATE_OP = 'CREATED';
18
- export var PRESENCE_REMOVE_OP = 'REMOVED';
19
- export var PRESENCE_INIT_OP = 'INIT';
20
- export var SOCKET_STATUS = {
21
- CLOSED: 'closed',
22
- CONNECTING: 'connecting',
23
- RECONNECTING: 'reconnecting',
24
- IDENTIFYING: 'identifying',
25
- UNIDENTIFIED: 'unidentified',
26
- IDENTIFIED: 'identified'
27
- };
28
- export var SOCKET_STAGE = {
29
- CLOSED: 'closed',
30
- CONNECTING: 'connecting',
31
- RECONNECTING: 'reconnecting',
32
- IDENTIFIED: 'connected'
33
- };
34
- export var Socket = /*#__PURE__*/function () {
35
- function Socket(uri) {
36
- _classCallCheck(this, Socket);
37
-
38
- this.uri = uri;
39
- this.status = SOCKET_STATUS.CLOSED;
40
- this.stage = SOCKET_STAGE.CLOSED;
41
- this.socket = null;
42
- this.token = '';
43
- this.ref = 0;
44
- this.topics = {};
45
- this.eventCallbacks = VALID_EVENTS.reduce(function (ec, e) {
46
- ec[e] = [];
47
- return ec;
48
- }, {}); // Bind functions that are used in callbacks.
49
-
50
- this.handleReconnect = this.handleReconnect.bind(this);
51
- this.handleIdentify = this.handleIdentify.bind(this);
52
- this.refCallbacks = [];
53
- this.heartbeatInterval = null; // Add our internal identify callback to keep track of whether we're identified.
54
-
55
- this.eventCallbacks.identify.push(this.handleIdentify);
56
- this.reconnectTimer = new Timer(this.handleReconnect);
57
- }
58
-
59
- _createClass(Socket, [{
60
- key: "isIdentified",
61
- value: function isIdentified() {
62
- return this.identified;
63
- }
64
- }, {
65
- key: "on",
66
- value: function on(event, cb) {
67
- if (!VALID_EVENTS.includes(event)) return this;
68
- this.eventCallbacks[event].push(cb);
69
- return this;
70
- }
71
- }, {
72
- key: "connect",
73
- value: function connect(token, uri) {
74
- this.token = token;
75
-
76
- if (uri) {
77
- this.uri = uri;
78
- }
79
-
80
- this.setStatus(SOCKET_STATUS.CONNECTING);
81
- this.doConnect();
82
- return this;
83
- }
84
- }, {
85
- key: "doConnect",
86
- value: function doConnect() {
87
- var _this = this;
88
-
89
- this.socket = new WebSocket(this.uri);
90
-
91
- this.socket.onopen = function (e) {
92
- return _this.handleConnect(e);
93
- };
94
-
95
- this.socket.onclose = function (e) {
96
- return _this.handleClose(e);
97
- };
98
-
99
- this.socket.onmessage = function (e) {
100
- return _this.receive(e.data);
101
- };
102
- }
103
- }, {
104
- key: "reconnect",
105
- value: function reconnect(token, uri) {
106
- this.close();
107
- this.token = token;
108
-
109
- if (uri) {
110
- this.uri = uri;
111
- }
112
-
113
- this.setStatus(SOCKET_STATUS.CONNECTING);
114
- this.doConnect();
115
- return this;
116
- }
117
- }, {
118
- key: "close",
119
- value: function close() {
120
- this.setStatus(SOCKET_STATUS.CLOSED);
121
- this.socket.close();
122
- clearInterval(this.heartbeatInterval);
123
- return this;
124
- }
125
- }, {
126
- key: "topic",
127
- value: function topic(topicId, cb) {
128
- if (this.topics.hasOwnProperty(topicId)) {
129
- console.warn('The client code attempted to join an already active topic.');
130
- return this.topics[topicId];
131
- }
132
-
133
- var topic = new Topic(topicId, this, cb);
134
- this.topics[topicId] = topic;
135
- return topic;
136
- }
137
- }, {
138
- key: "handleReconnect",
139
- value: function handleReconnect() {
140
- console.log('Trying to reconnect...');
141
- delete this.socket;
142
- this.doConnect();
143
- }
144
- }, {
145
- key: "handleConnect",
146
- value: function handleConnect(e) {
147
- var _this2 = this;
148
-
149
- // Identification callback.
150
- var previousStatus = this.status;
151
-
152
- var identCallback = function identCallback(message) {
153
- _this2.eventCallbacks.identify.forEach(function (cb) {
154
- return cb(message);
155
- }); // If we were reconnecting...
156
-
157
-
158
- if (previousStatus === SOCKET_STATUS.RECONNECTING) {
159
- console.log('Reconnected and identified. Attempting to re-subscribe to topics.', _this2.topics);
160
-
161
- _this2.forAllTopics(function (t) {
162
- return t.subscribe();
163
- });
164
- }
165
- }; // If I've just connected I am connected but not identified.
166
-
167
-
168
- this.setStatus(SOCKET_STATUS.IDENTIFYING, e); // Reset the reconnect timer if it is running.
169
-
170
- this.reconnectTimer.reset(); // Start our heartbeat interval.
171
-
172
- this.heartbeatInterval = setInterval(function () {
173
- return _this2.send(_this2.createMessage(TOPIC_HUB_TOPIC, TOPIC_HUB_ACTION_HEARTBEAT));
174
- }, TOPIC_HUB_HEARTBEAT_INTERVAL); // Send the "identify" message.
175
-
176
- var message = this.createMessage(TOPIC_HUB_TOPIC, TOPIC_HUB_ACTION_IDENTIFY, {
177
- token: this.token
178
- });
179
- this.send(message, identCallback);
180
- }
181
- }, {
182
- key: "handleClose",
183
- value: function handleClose(e) {
184
- if (this.status === SOCKET_STATUS.IDENTIFIED) {
185
- // If we were connected (e.g. the close isn't due to explicitly requesting
186
- // the socket to be closed) we should begin the reconnect process.
187
- this.setStatus(SOCKET_STATUS.RECONNECTING, e);
188
- this.forAllTopics(function (t) {
189
- return t.setStatus(TOPIC_STATUS.reconnecting);
190
- });
191
- this.reconnectTimer.execute();
192
- } else if (this.status === SOCKET_STATUS.RECONNECTING) {
193
- // If we're getting a close event and we're reconnecting that indicates that a
194
- // reconnect attempt failed and we will try again.
195
- this.setStatus(SOCKET_STATUS.RECONNECTING, e);
196
- this.reconnectTimer.execute();
197
- return;
198
- } else {
199
- this.setStatus(SOCKET_STATUS.CLOSED, e);
200
- this.forAllTopics(function (t) {
201
- return t.setStatus(TOPIC_STATUS.closed);
202
- });
203
- } // Call all of the event callbacks for 'connect'.
204
-
205
-
206
- this.eventCallbacks.disconnect.forEach(function (cb) {
207
- return cb(e);
208
- }); // TODO:MTR
209
- // Also close all of the topics.
210
- // this.topics.forEach(t => (t.topicStatus = TOPIC_STATUS.closed));
211
-
212
- clearInterval(this.heartbeatInterval);
213
- }
214
- }, {
215
- key: "handleIdentify",
216
- value: function handleIdentify(message) {
217
- if (message.event === TOPIC_HUB_EVENT_ACK_OK) {
218
- this.setStatus(SOCKET_STATUS.IDENTIFIED);
219
- } else {
220
- this.setStatus(SOCKET_STATUS.UNIDENTIFIED);
221
- }
222
- }
223
- }, {
224
- key: "send",
225
- value: function send(message, cb) {
226
- if (typeof cb === 'function') {
227
- this.refCallbacks.push({
228
- ref: message.ref,
229
- cb: cb
230
- });
231
- }
232
-
233
- this.socket.send(JSON.stringify(message));
234
- }
235
- }, {
236
- key: "receive",
237
- value: function receive(data) {
238
- try {
239
- // Parse the incoming message.
240
- var message = JSON.parse(data);
241
-
242
- if (message.ref) {
243
- // If the server sent a ref back then we should check for any ref callbacks.
244
- // Apply all ref callbacks where the ref matches the one on the message.
245
- this.refCallbacks.filter(function (r) {
246
- return r.ref === message.ref;
247
- }).forEach(function (r) {
248
- return r.cb(message);
249
- });
250
- } // Filter out the ref callbacks for this message.
251
-
252
-
253
- this.refCallbacks = this.refCallbacks.filter(function (r) {
254
- return r.ref !== message.ref;
255
- }); // If the message is a presence related message, lets handle it specially.
256
-
257
- if (message.topic === TOPIC_HUB_TOPIC && message.event === TOPIC_HUB_EVENT_PRESENCE) {
258
- this.receivePresence(message);
259
- } // Delegate it to the relevant topic.
260
-
261
-
262
- var topic = this.topics[message.event === 'unsubscribed' ? message.payload.topic : message.topic];
263
-
264
- if (topic) {
265
- topic.receive(message);
266
- } // If the event is 'unsubscribed' delete the topic.
267
-
268
-
269
- if (message.event === 'unsubscribed') {
270
- delete this.topics[message.payload.topic];
271
- }
272
- } catch (e) {
273
- console.warn('Received invalid message from server: ', data, e);
274
- }
275
- }
276
- }, {
277
- key: "receivePresence",
278
- value: function receivePresence(message) {
279
- var _this3 = this;
280
-
281
- if ([PRESENCE_CREATE_OP, PRESENCE_REMOVE_OP].includes(message.payload.op)) {
282
- this.processPresence(message.payload.op, message.payload.presenceData);
283
- } else if (message.payload.op === PRESENCE_INIT_OP) {
284
- message.payload.presences.forEach(function (pd) {
285
- _this3.processPresence(PRESENCE_CREATE_OP, pd);
286
- });
287
- }
288
- }
289
- }, {
290
- key: "processPresence",
291
- value: function processPresence(op, presenceData) {
292
- // If it's a standard delta message, fetch the topic
293
- var topic = this.topics[presenceData.topic];
294
-
295
- if (topic) {
296
- topic.receivePresence(op, presenceData);
297
- }
298
- }
299
- }, {
300
- key: "createMessage",
301
- value: function createMessage(topic, action, payload) {
302
- return {
303
- topic: topic,
304
- action: action,
305
- payload: payload,
306
- ref: this.makeRef()
307
- };
308
- }
309
- }, {
310
- key: "makeRef",
311
- value: function makeRef() {
312
- this.ref = this.ref === this.ref + 1 ? 0 : this.ref + 1;
313
- return '' + this.ref;
314
- }
315
- }, {
316
- key: "setStatus",
317
- value: function setStatus(status, event) {
318
- var stage = this.stage;
319
-
320
- if (status === SOCKET_STATUS.CLOSED) {
321
- stage = SOCKET_STAGE.CLOSED;
322
- } else if (status === SOCKET_STATUS.CONNECTING) {
323
- stage = SOCKET_STAGE.CONNECTING;
324
- } else if (status === SOCKET_STATUS.RECONNECTING) {
325
- stage = SOCKET_STAGE.RECONNECTING;
326
- } else if (status === SOCKET_STATUS.IDENTIFIED) {
327
- stage = SOCKET_STAGE.IDENTIFIED;
328
- }
329
-
330
- this.stage = stage;
331
- this.status = status;
332
- this.eventCallbacks.status.forEach(function (cb) {
333
- return cb(status, stage, event);
334
- });
335
- }
336
- }, {
337
- key: "forAllTopics",
338
- value: function forAllTopics(fn) {
339
- Object.entries(this.topics).forEach(function (_ref) {
340
- var _ref2 = _slicedToArray(_ref, 2),
341
- _topicId = _ref2[0],
342
- topic = _ref2[1];
343
-
344
- return fn(topic);
345
- });
346
- }
347
- }]);
348
-
349
- return Socket;
350
- }();
@@ -1,90 +0,0 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- import WS from 'jest-websocket-mock';
4
- import { Socket, SOCKET_STAGE, SOCKET_STATUS } from './socket';
5
- var MOCK_SERVER = 'ws://localhost:1234';
6
- var MOCK_TOKEN = 'JWT_TOKEN';
7
- describe('socket', function () {
8
- var socket;
9
- var server;
10
- beforeEach(function () {
11
- server = new WS(MOCK_SERVER);
12
- socket = new Socket(MOCK_SERVER);
13
- });
14
- afterEach(function () {
15
- WS.clean();
16
- });
17
- describe('typical flow', function () {
18
- test('connect', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
19
- var identifyCb, disconnectCb;
20
- return _regeneratorRuntime.wrap(function _callee$(_context) {
21
- while (1) {
22
- switch (_context.prev = _context.next) {
23
- case 0:
24
- identifyCb = jest.fn();
25
- disconnectCb = jest.fn();
26
- socket.on('identify', identifyCb);
27
- socket.on('disconnect', disconnectCb);
28
- expect(socket.stage).toBe(SOCKET_STAGE.CLOSED);
29
- expect(socket.status).toBe(SOCKET_STATUS.CLOSED);
30
- socket.connect(MOCK_TOKEN);
31
- expect(socket.stage).toBe(SOCKET_STAGE.CONNECTING);
32
- expect(socket.status).toBe(SOCKET_STATUS.CONNECTING);
33
- _context.next = 11;
34
- return server.connected;
35
-
36
- case 11:
37
- expect(socket.stage).toBe(SOCKET_STAGE.CONNECTING);
38
- expect(socket.status).toBe(SOCKET_STATUS.IDENTIFYING); // The Socket will send an identify automatically with the token.
39
-
40
- _context.next = 15;
41
- return expect(server).toReceiveMessage("{\"topic\":\"topichub\",\"action\":\"identify\",\"payload\":{\"token\":\"".concat(MOCK_TOKEN, "\"},\"ref\":\"").concat(socket.ref, "\"}"));
42
-
43
- case 15:
44
- _context.next = 17;
45
- return server.send("{ \"event\": \"ack-ok\", \"ref\": \"".concat(socket.ref, "\" }"));
46
-
47
- case 17:
48
- expect(socket.stage).toBe(SOCKET_STAGE.IDENTIFIED);
49
- expect(socket.status).toBe(SOCKET_STATUS.IDENTIFIED); // Close and restart the mock.
50
-
51
- _context.next = 21;
52
- return server.close();
53
-
54
- case 21:
55
- _context.next = 23;
56
- return server.closed;
57
-
58
- case 23:
59
- WS.clean();
60
- server = new WS(MOCK_SERVER);
61
- expect(disconnectCb).toHaveBeenCalled();
62
- expect(socket.stage).toBe(SOCKET_STAGE.RECONNECTING);
63
- expect(socket.status).toBe(SOCKET_STATUS.RECONNECTING);
64
- _context.next = 30;
65
- return server.connected;
66
-
67
- case 30:
68
- expect(socket.stage).toBe(SOCKET_STAGE.RECONNECTING);
69
- expect(socket.status).toBe(SOCKET_STATUS.IDENTIFYING);
70
- _context.next = 34;
71
- return expect(server).toReceiveMessage("{\"topic\":\"topichub\",\"action\":\"identify\",\"payload\":{\"token\":\"".concat(MOCK_TOKEN, "\"},\"ref\":\"").concat(socket.ref, "\"}"));
72
-
73
- case 34:
74
- _context.next = 36;
75
- return server.send("{ \"event\": \"ack-ok\", \"ref\": \"".concat(socket.ref, "\" }"));
76
-
77
- case 36:
78
- expect(identifyCb).toHaveBeenCalled();
79
- expect(socket.stage).toBe(SOCKET_STAGE.IDENTIFIED);
80
- expect(socket.status).toBe(SOCKET_STATUS.IDENTIFIED);
81
-
82
- case 39:
83
- case "end":
84
- return _context.stop();
85
- }
86
- }
87
- }, _callee);
88
- })));
89
- });
90
- });
@@ -1,45 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
-
4
- var DEFAULT_TIMING_FN = function DEFAULT_TIMING_FN(attempts) {
5
- return [500, 1000, 5000, 10000][attempts] || 10000;
6
- };
7
-
8
- export var Timer = /*#__PURE__*/function () {
9
- function Timer(callback, timingFn) {
10
- _classCallCheck(this, Timer);
11
-
12
- this.callback = callback;
13
- this.timingFn = timingFn || DEFAULT_TIMING_FN;
14
- this.attempts = 0;
15
- this.timeout = null;
16
- }
17
-
18
- _createClass(Timer, [{
19
- key: "reset",
20
- value: function reset() {
21
- this.attempts = 0;
22
- clearTimeout(this.timeout);
23
- this.timeout = null;
24
- }
25
- }, {
26
- key: "isRunning",
27
- value: function isRunning() {
28
- return this.timeout !== null;
29
- }
30
- }, {
31
- key: "execute",
32
- value: function execute() {
33
- var _this = this;
34
-
35
- clearTimeout(this.timeout);
36
- this.timeout = setTimeout(function () {
37
- _this.attempts = _this.attempts + 1;
38
-
39
- _this.callback();
40
- }, this.timingFn(this.attempts));
41
- }
42
- }]);
43
-
44
- return Timer;
45
- }();
@@ -1,51 +0,0 @@
1
- import { Timer } from './timer';
2
- jest.useFakeTimers();
3
- describe('Timer', function () {
4
- var callback;
5
- beforeEach(function () {
6
- callback = jest.fn();
7
- });
8
- test('callback is called after the timeout', function () {
9
- var timer = new Timer(callback);
10
- expect(timer.attempts).toBe(0);
11
- expect(callback).not.toBeCalled();
12
- timer.execute();
13
- jest.runAllTimers();
14
- expect(timer.attempts).toBe(1);
15
- expect(callback).toBeCalled();
16
- expect(callback).toHaveBeenCalledTimes(1);
17
- });
18
- test('callback is called each time', function () {
19
- var timer = new Timer(callback);
20
- timer.execute();
21
- jest.runAllTimers();
22
- timer.execute();
23
- jest.runAllTimers();
24
- expect(timer.attempts).toBe(2);
25
- expect(callback).toBeCalled();
26
- expect(callback).toHaveBeenCalledTimes(2);
27
- });
28
- test('gets the next timeout using attempts', function () {
29
- var timingFn = jest.fn();
30
- var timer = new Timer(callback, timingFn);
31
- timer.attempts = 2;
32
- timer.execute();
33
- jest.runAllTimers();
34
- expect(timingFn).toBeCalled();
35
- expect(timingFn).toHaveBeenCalledTimes(1);
36
- expect(timingFn).toBeCalledWith(2);
37
- expect(timer.attempts).toBe(3);
38
- });
39
- test('reset sets clears the attempts and timeout', function () {
40
- var timer = new Timer(callback, function () {
41
- return 1000;
42
- });
43
- timer.attempts = 2;
44
- timer.execute();
45
- jest.runTimersToTime(500);
46
- timer.reset();
47
- jest.runAllTimers();
48
- expect(callback).not.toHaveBeenCalled();
49
- expect(timer.attempts).toBe(0);
50
- });
51
- });