@ledgerhq/device-management-kit 0.0.0-develop-20251104001220 → 0.0.0-develop-20251106001214

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 (173) hide show
  1. package/lib/cjs/package.json +1 -1
  2. package/lib/cjs/src/api/DeviceManagementKit.js +1 -1
  3. package/lib/cjs/src/api/DeviceManagementKit.js.map +2 -2
  4. package/lib/cjs/src/api/DeviceManagementKit.test.js +1 -1
  5. package/lib/cjs/src/api/DeviceManagementKit.test.js.map +2 -2
  6. package/lib/cjs/src/api/command/Command.js +1 -1
  7. package/lib/cjs/src/api/command/Command.js.map +1 -1
  8. package/lib/cjs/src/api/command/os/CloseAppCommand.js +1 -1
  9. package/lib/cjs/src/api/command/os/CloseAppCommand.js.map +2 -2
  10. package/lib/cjs/src/api/command/os/CloseAppCommand.test.js +1 -1
  11. package/lib/cjs/src/api/command/os/CloseAppCommand.test.js.map +2 -2
  12. package/lib/cjs/src/api/command/os/GetAppAndVersionCommand.js +1 -1
  13. package/lib/cjs/src/api/command/os/GetAppAndVersionCommand.js.map +2 -2
  14. package/lib/cjs/src/api/command/os/GetAppAndVersionCommand.test.js +1 -1
  15. package/lib/cjs/src/api/command/os/GetAppAndVersionCommand.test.js.map +2 -2
  16. package/lib/cjs/src/api/command/os/GetBatteryStatusCommand.js +1 -1
  17. package/lib/cjs/src/api/command/os/GetBatteryStatusCommand.js.map +2 -2
  18. package/lib/cjs/src/api/command/os/GetBatteryStatusCommand.test.js +1 -1
  19. package/lib/cjs/src/api/command/os/GetBatteryStatusCommand.test.js.map +3 -3
  20. package/lib/cjs/src/api/command/os/GetCustomImageSizeCommand.js +1 -1
  21. package/lib/cjs/src/api/command/os/GetCustomImageSizeCommand.js.map +2 -2
  22. package/lib/cjs/src/api/command/os/GetCustomImageSizeCommand.test.js +1 -1
  23. package/lib/cjs/src/api/command/os/GetCustomImageSizeCommand.test.js.map +2 -2
  24. package/lib/cjs/src/api/command/os/GetOsVersionCommand.js +1 -1
  25. package/lib/cjs/src/api/command/os/GetOsVersionCommand.js.map +2 -2
  26. package/lib/cjs/src/api/command/os/GetOsVersionCommand.test.js +1 -1
  27. package/lib/cjs/src/api/command/os/GetOsVersionCommand.test.js.map +2 -2
  28. package/lib/cjs/src/api/command/os/ListAppsCommand.js +1 -1
  29. package/lib/cjs/src/api/command/os/ListAppsCommand.js.map +2 -2
  30. package/lib/cjs/src/api/command/os/ListAppsCommand.test.js +1 -1
  31. package/lib/cjs/src/api/command/os/ListAppsCommand.test.js.map +2 -2
  32. package/lib/cjs/src/api/command/os/ListLanguagePackCommand.js +1 -1
  33. package/lib/cjs/src/api/command/os/ListLanguagePackCommand.js.map +2 -2
  34. package/lib/cjs/src/api/command/os/ListLanguagePackCommand.test.js +1 -1
  35. package/lib/cjs/src/api/command/os/ListLanguagePackCommand.test.js.map +2 -2
  36. package/lib/cjs/src/api/command/os/LoadCertificateCommand.js +1 -1
  37. package/lib/cjs/src/api/command/os/LoadCertificateCommand.js.map +2 -2
  38. package/lib/cjs/src/api/command/os/LoadCertificateCommand.test.js +1 -1
  39. package/lib/cjs/src/api/command/os/LoadCertificateCommand.test.js.map +3 -3
  40. package/lib/cjs/src/api/command/os/OpenAppCommand.js +1 -1
  41. package/lib/cjs/src/api/command/os/OpenAppCommand.js.map +2 -2
  42. package/lib/cjs/src/api/command/os/OpenAppCommand.test.js +1 -1
  43. package/lib/cjs/src/api/command/os/OpenAppCommand.test.js.map +2 -2
  44. package/lib/cjs/src/api/command/use-case/SendCommandUseCase.test.js +1 -1
  45. package/lib/cjs/src/api/command/use-case/SendCommandUseCase.test.js.map +2 -2
  46. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js +1 -1
  47. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js.map +2 -2
  48. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js +1 -1
  49. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js.map +2 -2
  50. package/lib/cjs/src/api/transport/model/ConnectedDevice.js +1 -1
  51. package/lib/cjs/src/api/transport/model/ConnectedDevice.js.map +3 -3
  52. package/lib/cjs/src/internal/device-session/model/DeviceSession.js +1 -1
  53. package/lib/cjs/src/internal/device-session/model/DeviceSession.js.map +2 -2
  54. package/lib/cjs/src/internal/discovery/di/discoveryModule.js +1 -1
  55. package/lib/cjs/src/internal/discovery/di/discoveryModule.js.map +3 -3
  56. package/lib/cjs/src/internal/discovery/di/discoveryModule.test.js +1 -1
  57. package/lib/cjs/src/internal/discovery/di/discoveryModule.test.js.map +3 -3
  58. package/lib/cjs/src/internal/discovery/di/discoveryTypes.js +1 -1
  59. package/lib/cjs/src/internal/discovery/di/discoveryTypes.js.map +2 -2
  60. package/lib/cjs/src/internal/discovery/use-case/ConnectUseCase.js +1 -1
  61. package/lib/cjs/src/internal/discovery/use-case/ConnectUseCase.js.map +3 -3
  62. package/lib/cjs/src/internal/discovery/use-case/ConnectUseCase.test.js +1 -1
  63. package/lib/cjs/src/internal/discovery/use-case/ConnectUseCase.test.js.map +3 -3
  64. package/lib/cjs/src/internal/discovery/use-case/DisconnectUseCase.js +1 -1
  65. package/lib/cjs/src/internal/discovery/use-case/DisconnectUseCase.js.map +3 -3
  66. package/lib/cjs/src/internal/discovery/use-case/ReconnectUseCase.js +2 -0
  67. package/lib/cjs/src/internal/discovery/use-case/ReconnectUseCase.js.map +7 -0
  68. package/lib/cjs/src/internal/discovery/use-case/ReconnectUseCase.test.js +2 -0
  69. package/lib/cjs/src/internal/discovery/use-case/ReconnectUseCase.test.js.map +7 -0
  70. package/lib/esm/package.json +1 -1
  71. package/lib/esm/src/api/DeviceManagementKit.js +1 -1
  72. package/lib/esm/src/api/DeviceManagementKit.js.map +2 -2
  73. package/lib/esm/src/api/DeviceManagementKit.test.js +1 -1
  74. package/lib/esm/src/api/DeviceManagementKit.test.js.map +2 -2
  75. package/lib/esm/src/api/command/os/CloseAppCommand.js +1 -1
  76. package/lib/esm/src/api/command/os/CloseAppCommand.js.map +2 -2
  77. package/lib/esm/src/api/command/os/CloseAppCommand.test.js +1 -1
  78. package/lib/esm/src/api/command/os/CloseAppCommand.test.js.map +2 -2
  79. package/lib/esm/src/api/command/os/GetAppAndVersionCommand.js +1 -1
  80. package/lib/esm/src/api/command/os/GetAppAndVersionCommand.js.map +2 -2
  81. package/lib/esm/src/api/command/os/GetAppAndVersionCommand.test.js +1 -1
  82. package/lib/esm/src/api/command/os/GetAppAndVersionCommand.test.js.map +2 -2
  83. package/lib/esm/src/api/command/os/GetBatteryStatusCommand.js +1 -1
  84. package/lib/esm/src/api/command/os/GetBatteryStatusCommand.js.map +2 -2
  85. package/lib/esm/src/api/command/os/GetBatteryStatusCommand.test.js +1 -1
  86. package/lib/esm/src/api/command/os/GetBatteryStatusCommand.test.js.map +3 -3
  87. package/lib/esm/src/api/command/os/GetCustomImageSizeCommand.js +1 -1
  88. package/lib/esm/src/api/command/os/GetCustomImageSizeCommand.js.map +2 -2
  89. package/lib/esm/src/api/command/os/GetCustomImageSizeCommand.test.js +1 -1
  90. package/lib/esm/src/api/command/os/GetCustomImageSizeCommand.test.js.map +2 -2
  91. package/lib/esm/src/api/command/os/GetOsVersionCommand.js +1 -1
  92. package/lib/esm/src/api/command/os/GetOsVersionCommand.js.map +2 -2
  93. package/lib/esm/src/api/command/os/GetOsVersionCommand.test.js +1 -1
  94. package/lib/esm/src/api/command/os/GetOsVersionCommand.test.js.map +2 -2
  95. package/lib/esm/src/api/command/os/ListAppsCommand.js +1 -1
  96. package/lib/esm/src/api/command/os/ListAppsCommand.js.map +2 -2
  97. package/lib/esm/src/api/command/os/ListAppsCommand.test.js +1 -1
  98. package/lib/esm/src/api/command/os/ListAppsCommand.test.js.map +2 -2
  99. package/lib/esm/src/api/command/os/ListLanguagePackCommand.js +1 -1
  100. package/lib/esm/src/api/command/os/ListLanguagePackCommand.js.map +2 -2
  101. package/lib/esm/src/api/command/os/ListLanguagePackCommand.test.js +1 -1
  102. package/lib/esm/src/api/command/os/ListLanguagePackCommand.test.js.map +2 -2
  103. package/lib/esm/src/api/command/os/LoadCertificateCommand.js +1 -1
  104. package/lib/esm/src/api/command/os/LoadCertificateCommand.js.map +2 -2
  105. package/lib/esm/src/api/command/os/LoadCertificateCommand.test.js +1 -1
  106. package/lib/esm/src/api/command/os/LoadCertificateCommand.test.js.map +3 -3
  107. package/lib/esm/src/api/command/os/OpenAppCommand.js +1 -1
  108. package/lib/esm/src/api/command/os/OpenAppCommand.js.map +2 -2
  109. package/lib/esm/src/api/command/os/OpenAppCommand.test.js +1 -1
  110. package/lib/esm/src/api/command/os/OpenAppCommand.test.js.map +2 -2
  111. package/lib/esm/src/api/command/use-case/SendCommandUseCase.test.js +1 -1
  112. package/lib/esm/src/api/command/use-case/SendCommandUseCase.test.js.map +2 -2
  113. package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js +1 -1
  114. package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js.map +2 -2
  115. package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js +1 -1
  116. package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js.map +2 -2
  117. package/lib/esm/src/api/transport/model/ConnectedDevice.js +1 -1
  118. package/lib/esm/src/api/transport/model/ConnectedDevice.js.map +3 -3
  119. package/lib/esm/src/internal/device-session/model/DeviceSession.js +1 -1
  120. package/lib/esm/src/internal/device-session/model/DeviceSession.js.map +2 -2
  121. package/lib/esm/src/internal/discovery/di/discoveryModule.js +1 -1
  122. package/lib/esm/src/internal/discovery/di/discoveryModule.js.map +3 -3
  123. package/lib/esm/src/internal/discovery/di/discoveryModule.test.js +1 -1
  124. package/lib/esm/src/internal/discovery/di/discoveryModule.test.js.map +3 -3
  125. package/lib/esm/src/internal/discovery/di/discoveryTypes.js +1 -1
  126. package/lib/esm/src/internal/discovery/di/discoveryTypes.js.map +2 -2
  127. package/lib/esm/src/internal/discovery/use-case/ConnectUseCase.js +1 -1
  128. package/lib/esm/src/internal/discovery/use-case/ConnectUseCase.js.map +3 -3
  129. package/lib/esm/src/internal/discovery/use-case/ConnectUseCase.test.js +1 -1
  130. package/lib/esm/src/internal/discovery/use-case/ConnectUseCase.test.js.map +3 -3
  131. package/lib/esm/src/internal/discovery/use-case/DisconnectUseCase.js +1 -1
  132. package/lib/esm/src/internal/discovery/use-case/DisconnectUseCase.js.map +3 -3
  133. package/lib/esm/src/internal/discovery/use-case/ReconnectUseCase.js +2 -0
  134. package/lib/esm/src/internal/discovery/use-case/ReconnectUseCase.js.map +7 -0
  135. package/lib/esm/src/internal/discovery/use-case/ReconnectUseCase.test.js +2 -0
  136. package/lib/esm/src/internal/discovery/use-case/ReconnectUseCase.test.js.map +7 -0
  137. package/lib/types/src/api/DeviceManagementKit.d.ts +12 -0
  138. package/lib/types/src/api/DeviceManagementKit.d.ts.map +1 -1
  139. package/lib/types/src/api/command/Command.d.ts +4 -0
  140. package/lib/types/src/api/command/Command.d.ts.map +1 -1
  141. package/lib/types/src/api/command/os/CloseAppCommand.d.ts +1 -0
  142. package/lib/types/src/api/command/os/CloseAppCommand.d.ts.map +1 -1
  143. package/lib/types/src/api/command/os/GetAppAndVersionCommand.d.ts +1 -0
  144. package/lib/types/src/api/command/os/GetAppAndVersionCommand.d.ts.map +1 -1
  145. package/lib/types/src/api/command/os/GetBatteryStatusCommand.d.ts +1 -0
  146. package/lib/types/src/api/command/os/GetBatteryStatusCommand.d.ts.map +1 -1
  147. package/lib/types/src/api/command/os/GetCustomImageSizeCommand.d.ts +1 -0
  148. package/lib/types/src/api/command/os/GetCustomImageSizeCommand.d.ts.map +1 -1
  149. package/lib/types/src/api/command/os/GetOsVersionCommand.d.ts +1 -0
  150. package/lib/types/src/api/command/os/GetOsVersionCommand.d.ts.map +1 -1
  151. package/lib/types/src/api/command/os/ListAppsCommand.d.ts +1 -0
  152. package/lib/types/src/api/command/os/ListAppsCommand.d.ts.map +1 -1
  153. package/lib/types/src/api/command/os/ListLanguagePackCommand.d.ts +1 -0
  154. package/lib/types/src/api/command/os/ListLanguagePackCommand.d.ts.map +1 -1
  155. package/lib/types/src/api/command/os/LoadCertificateCommand.d.ts +1 -0
  156. package/lib/types/src/api/command/os/LoadCertificateCommand.d.ts.map +1 -1
  157. package/lib/types/src/api/command/os/OpenAppCommand.d.ts +1 -0
  158. package/lib/types/src/api/command/os/OpenAppCommand.d.ts.map +1 -1
  159. package/lib/types/src/api/transport/model/ConnectedDevice.d.ts +3 -2
  160. package/lib/types/src/api/transport/model/ConnectedDevice.d.ts.map +1 -1
  161. package/lib/types/src/internal/device-session/model/DeviceSession.d.ts.map +1 -1
  162. package/lib/types/src/internal/discovery/di/discoveryModule.d.ts.map +1 -1
  163. package/lib/types/src/internal/discovery/di/discoveryTypes.d.ts +1 -0
  164. package/lib/types/src/internal/discovery/di/discoveryTypes.d.ts.map +1 -1
  165. package/lib/types/src/internal/discovery/use-case/ConnectUseCase.d.ts +3 -2
  166. package/lib/types/src/internal/discovery/use-case/ConnectUseCase.d.ts.map +1 -1
  167. package/lib/types/src/internal/discovery/use-case/DisconnectUseCase.d.ts.map +1 -1
  168. package/lib/types/src/internal/discovery/use-case/ReconnectUseCase.d.ts +32 -0
  169. package/lib/types/src/internal/discovery/use-case/ReconnectUseCase.d.ts.map +1 -0
  170. package/lib/types/src/internal/discovery/use-case/ReconnectUseCase.test.d.ts +2 -0
  171. package/lib/types/src/internal/discovery/use-case/ReconnectUseCase.test.d.ts.map +1 -0
  172. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  173. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.ts"],
4
- "sourcesContent": ["/* eslint @typescript-eslint/consistent-type-imports:0 */\nimport { Left, Right } from \"purify-ts\";\nimport { type Mock } from \"vitest\";\nimport { assign, createMachine } from \"xstate\";\n\nimport { type Apdu } from \"@api/apdu/model/Apdu\";\nimport { ApduBuilder } from \"@api/apdu/utils/ApduBuilder\";\nimport { CommandResultFactory } from \"@api/command/model/CommandResult\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { testDeviceActionStates } from \"@api/device-action/__test-utils__/testDeviceActionStates\";\nimport {\n type DeviceActionState,\n DeviceActionStatus,\n} from \"@api/device-action/model/DeviceActionState\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { type Command } from \"@api/types\";\nimport { UnknownDeviceExchangeError } from \"@root/src\";\n\nimport { CallTaskInAppDeviceAction } from \"./CallTaskInAppDeviceAction\";\nimport {\n type CallTaskInAppDAError,\n type CallTaskInAppDAIntermediateValue,\n type CallTaskInAppDAOutput,\n} from \"./CallTaskInAppDeviceActionTypes\";\n\nvi.mock(\n \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\",\n async (importOriginal) => {\n const original =\n await importOriginal<\n typeof import(\"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\")\n >();\n return {\n ...original,\n OpenAppDeviceAction: vi.fn(() => ({\n ...original.OpenAppDeviceAction,\n makeStateMachine: vi.fn(),\n })),\n };\n },\n);\n\nconst setupOpenAppDAMock = (error?: unknown) => {\n (OpenAppDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n initial: \"pending\",\n states: {\n pending: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n }),\n after: {\n 0: \"done\",\n },\n },\n done: {\n type: \"final\",\n },\n },\n output: () => (error ? Left(error) : Right(undefined)),\n }),\n ),\n }));\n};\n\ndescribe(\"CallTaskInAppDeviceAction\", () => {\n const callMyTask = vi.fn();\n\n const extractDependenciesMock = () => ({\n callTask: callMyTask,\n });\n\n const { sendCommand: apiSendCommandMock } = makeDeviceActionInternalApiMock();\n\n const commandParams = {\n paramString: \"aParameter\",\n paramNumber: 1234,\n };\n const mockedCommandResponse = {\n aNumber: 5678,\n aString: \"mockedResponseString\",\n };\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"without mocking extractDependencies\", () => {\n it(\"should call sendCommand on internalApi with the correct parameters\", async () => {\n setupOpenAppDAMock();\n apiSendCommandMock.mockResolvedValue(\n CommandResultFactory({ data: undefined }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n await new Promise<void>((resolve, reject) => {\n deviceAction\n ._execute(makeDeviceActionInternalApiMock())\n .observable.subscribe({\n error: () => reject(),\n complete: () => resolve(),\n next: () => {},\n });\n });\n\n expect(apiSendCommandMock).toHaveBeenCalledWith(\n new TestCommand(commandParams),\n );\n });\n });\n\n describe(\"error cases\", () => {\n it(\"should error and output the error if the open app fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock(new UnknownDAError(\"Mocked error\"));\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"Mocked error\"),\n },\n ];\n\n testDeviceActionStates(\n new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n }),\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should error and output an error if the call task fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n callMyTask.mockResolvedValue(\n CommandResultFactory({\n error: new UnknownDeviceExchangeError(\"Mocked error\"),\n }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDeviceExchangeError(\"Mocked error\"),\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"success cases\", () => {\n it(\"should succeed and output the command result if the send command succeeds\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n callMyTask.mockResolvedValue(\n CommandResultFactory({ data: mockedCommandResponse }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Completed,\n output: mockedCommandResponse,\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should succeed while skipping OpenApp\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n callMyTask.mockResolvedValue(\n CommandResultFactory({ data: mockedCommandResponse }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: true,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Completed,\n output: mockedCommandResponse,\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n});\n\ntype MyCommandResponse = {\n aNumber: number;\n aString: string;\n};\n\ntype MyCommandParams = {\n paramString: string;\n paramNumber: number;\n};\n\nclass TestCommand implements Command<MyCommandResponse, MyCommandParams> {\n params: MyCommandParams;\n constructor(params: MyCommandParams) {\n this.params = params;\n }\n getApdu(): Apdu {\n return new ApduBuilder({ cla: 0x00, ins: 0x01, p1: 0x02, p2: 0x03 })\n .add32BitUIntToData(this.params.paramNumber)\n .addAsciiStringToData(this.params.paramString)\n .build();\n }\n parseResponse() {\n return CommandResultFactory({ data: { aNumber: 1, aString: \"aString\" } });\n }\n}\n\ntype MyCommandCallTaskDAState = DeviceActionState<\n CallTaskInAppDAOutput<MyCommandResponse>,\n CallTaskInAppDAError<UnknownDAError>,\n CallTaskInAppDAIntermediateValue<\n UserInteractionRequired.None | UserInteractionRequired.VerifyAddress\n >\n>;\n"],
5
- "mappings": "AACA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,UAAAC,EAAQ,iBAAAC,MAAqB,SAGtC,OAAS,eAAAC,MAAmB,8BAC5B,OAAS,wBAAAC,MAA4B,mCACrC,OAAS,mCAAAC,MAAuC,oDAChD,OAAS,0BAAAC,MAA8B,2DACvC,OAEE,sBAAAC,MACK,6CACP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,kBAAAC,MAAsB,+BAC/B,OAAS,uBAAAC,MAA2B,gEAEpC,OAAS,8BAAAC,MAAkC,YAE3C,OAAS,6BAAAC,MAAiC,8BAO1C,GAAG,KACD,gEACA,MAAOC,GAAmB,CACxB,MAAMC,EACJ,MAAMD,EAEJ,EACJ,MAAO,CACL,GAAGC,EACH,oBAAqB,GAAG,GAAG,KAAO,CAChC,GAAGA,EAAS,oBACZ,iBAAkB,GAAG,GAAG,CAC1B,EAAE,CACJ,CACF,CACF,EAEA,MAAMC,EAAsBC,GAAoB,CAC7CN,EAA6B,mBAAmB,KAAO,CACtD,iBAAkB,GAAG,GAAG,EAAE,mBAAmB,IAC3CR,EAAc,CACZ,QAAS,UACT,OAAQ,CACN,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AmB,QAC3B,kBAAmB,CACjB,wBAAyBC,EAAwB,aACnD,CACF,EACA,CACE,OAAQD,EAAmB,UAC3B,OAAQc,CACV,CACF,EAEAf,EACEgB,EACAK,EACAtB,EAAgC,EAChC,CACE,OAAQoB,EACR,QAASC,CACX,CACF,CACF,CAAC,CAAC,CACN,CAAC,CACH,CAAC,EAYD,MAAMF,CAAmE,CACvE,OACA,YAAYI,EAAyB,CACnC,KAAK,OAASA,CAChB,CACA,SAAgB,CACd,OAAO,IAAIzB,EAAY,CAAE,IAAK,EAAM,IAAK,EAAM,GAAI,EAAM,GAAI,CAAK,CAAC,EAChE,mBAAmB,KAAK,OAAO,WAAW,EAC1C,qBAAqB,KAAK,OAAO,WAAW,EAC5C,MAAM,CACX,CACA,eAAgB,CACd,OAAOC,EAAqB,CAAE,KAAM,CAAE,QAAS,EAAG,QAAS,SAAU,CAAE,CAAC,CAC1E,CACF",
4
+ "sourcesContent": ["/* eslint @typescript-eslint/consistent-type-imports:0 */\nimport { Left, Right } from \"purify-ts\";\nimport { type Mock } from \"vitest\";\nimport { assign, createMachine } from \"xstate\";\n\nimport { type Apdu } from \"@api/apdu/model/Apdu\";\nimport { ApduBuilder } from \"@api/apdu/utils/ApduBuilder\";\nimport { CommandResultFactory } from \"@api/command/model/CommandResult\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { testDeviceActionStates } from \"@api/device-action/__test-utils__/testDeviceActionStates\";\nimport {\n type DeviceActionState,\n DeviceActionStatus,\n} from \"@api/device-action/model/DeviceActionState\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { type Command } from \"@api/types\";\nimport { UnknownDeviceExchangeError } from \"@root/src\";\n\nimport { CallTaskInAppDeviceAction } from \"./CallTaskInAppDeviceAction\";\nimport {\n type CallTaskInAppDAError,\n type CallTaskInAppDAIntermediateValue,\n type CallTaskInAppDAOutput,\n} from \"./CallTaskInAppDeviceActionTypes\";\n\nvi.mock(\n \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\",\n async (importOriginal) => {\n const original =\n await importOriginal<\n typeof import(\"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\")\n >();\n return {\n ...original,\n OpenAppDeviceAction: vi.fn(() => ({\n ...original.OpenAppDeviceAction,\n makeStateMachine: vi.fn(),\n })),\n };\n },\n);\n\nconst setupOpenAppDAMock = (error?: unknown) => {\n (OpenAppDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n initial: \"pending\",\n states: {\n pending: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n }),\n after: {\n 0: \"done\",\n },\n },\n done: {\n type: \"final\",\n },\n },\n output: () => (error ? Left(error) : Right(undefined)),\n }),\n ),\n }));\n};\n\ndescribe(\"CallTaskInAppDeviceAction\", () => {\n const callMyTask = vi.fn();\n\n const extractDependenciesMock = () => ({\n callTask: callMyTask,\n });\n\n const { sendCommand: apiSendCommandMock } = makeDeviceActionInternalApiMock();\n\n const commandParams = {\n paramString: \"aParameter\",\n paramNumber: 1234,\n };\n const mockedCommandResponse = {\n aNumber: 5678,\n aString: \"mockedResponseString\",\n };\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"without mocking extractDependencies\", () => {\n it(\"should call sendCommand on internalApi with the correct parameters\", async () => {\n setupOpenAppDAMock();\n apiSendCommandMock.mockResolvedValue(\n CommandResultFactory({ data: undefined }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n await new Promise<void>((resolve, reject) => {\n deviceAction\n ._execute(makeDeviceActionInternalApiMock())\n .observable.subscribe({\n error: () => reject(),\n complete: () => resolve(),\n next: () => {},\n });\n });\n\n expect(apiSendCommandMock).toHaveBeenCalledWith(\n new TestCommand(commandParams),\n );\n });\n });\n\n describe(\"error cases\", () => {\n it(\"should error and output the error if the open app fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock(new UnknownDAError(\"Mocked error\"));\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"Mocked error\"),\n },\n ];\n\n testDeviceActionStates(\n new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n }),\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should error and output an error if the call task fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n callMyTask.mockResolvedValue(\n CommandResultFactory({\n error: new UnknownDeviceExchangeError(\"Mocked error\"),\n }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDeviceExchangeError(\"Mocked error\"),\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"success cases\", () => {\n it(\"should succeed and output the command result if the send command succeeds\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n callMyTask.mockResolvedValue(\n CommandResultFactory({ data: mockedCommandResponse }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Completed,\n output: mockedCommandResponse,\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should succeed while skipping OpenApp\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n callMyTask.mockResolvedValue(\n CommandResultFactory({ data: mockedCommandResponse }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: true,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Completed,\n output: mockedCommandResponse,\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n});\n\ntype MyCommandResponse = {\n aNumber: number;\n aString: string;\n};\n\ntype MyCommandParams = {\n paramString: string;\n paramNumber: number;\n};\n\nclass TestCommand implements Command<MyCommandResponse, MyCommandParams> {\n readonly name = \"testCommand\";\n\n params: MyCommandParams;\n constructor(params: MyCommandParams) {\n this.params = params;\n }\n getApdu(): Apdu {\n return new ApduBuilder({ cla: 0x00, ins: 0x01, p1: 0x02, p2: 0x03 })\n .add32BitUIntToData(this.params.paramNumber)\n .addAsciiStringToData(this.params.paramString)\n .build();\n }\n parseResponse() {\n return CommandResultFactory({ data: { aNumber: 1, aString: \"aString\" } });\n }\n}\n\ntype MyCommandCallTaskDAState = DeviceActionState<\n CallTaskInAppDAOutput<MyCommandResponse>,\n CallTaskInAppDAError<UnknownDAError>,\n CallTaskInAppDAIntermediateValue<\n UserInteractionRequired.None | UserInteractionRequired.VerifyAddress\n >\n>;\n"],
5
+ "mappings": "AACA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,UAAAC,EAAQ,iBAAAC,MAAqB,SAGtC,OAAS,eAAAC,MAAmB,8BAC5B,OAAS,wBAAAC,MAA4B,mCACrC,OAAS,mC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aACnD,CACF,EACA,CACE,OAAQD,EAAmB,UAC3B,OAAQc,CACV,CACF,EAEAf,EACEgB,EACAK,EACAtB,EAAgC,EAChC,CACE,OAAQoB,EACR,QAASC,CACX,CACF,CACF,CAAC,CAAC,EAEJ,GAAG,wCAAyC,IAC1C,IAAI,QAAc,CAACD,EAASC,IAAW,CACrCX,EAAmB,EAEnBE,EAAW,kBACTb,EAAqB,CAAE,KAAMiB,CAAsB,CAAC,CACtD,EAEA,MAAMC,EAAe,IAAIV,EAA0B,CACjD,MAAO,CACL,KAAM,MAAOW,GACX,MAAMA,EAAY,YAAY,IAAIC,EAAYJ,CAAa,CAAC,EAC9D,QAAS,QACT,wBAAyBZ,EAAwB,cACjD,YAAa,EACf,CACF,CAAC,EAED,GAAG,MAAMc,EAAc,qBAAqB,EAAE,mBAC5CJ,CACF,EAEA,MAAMS,EAA6C,CACjD,CACE,OAAQpB,EAAmB,QAC3B,kBAAmB,CACjB,wBAAyBC,EAAwB,aACnD,CACF,EACA,CACE,OAAQD,EAAmB,UAC3B,OAAQc,CACV,CACF,EAEAf,EACEgB,EACAK,EACAtB,EAAgC,EAChC,CACE,OAAQoB,EACR,QAASC,CACX,CACF,CACF,CAAC,CAAC,CACN,CAAC,CACH,CAAC,EAYD,MAAMF,CAAmE,CAC9D,KAAO,cAEhB,OACA,YAAYI,EAAyB,CACnC,KAAK,OAASA,CAChB,CACA,SAAgB,CACd,OAAO,IAAIzB,EAAY,CAAE,IAAK,EAAM,IAAK,EAAM,GAAI,EAAM,GAAI,CAAK,CAAC,EAChE,mBAAmB,KAAK,OAAO,WAAW,EAC1C,qBAAqB,KAAK,OAAO,WAAW,EAC5C,MAAM,CACX,CACA,eAAgB,CACd,OAAOC,EAAqB,CAAE,KAAM,CAAE,QAAS,EAAG,QAAS,SAAU,CAAE,CAAC,CAC1E,CACF",
6
6
  "names": ["Left", "Right", "assign", "createMachine", "ApduBuilder", "CommandResultFactory", "makeDeviceActionInternalApiMock", "testDeviceActionStates", "DeviceActionStatus", "UserInteractionRequired", "UnknownDAError", "OpenAppDeviceAction", "UnknownDeviceExchangeError", "CallTaskInAppDeviceAction", "importOriginal", "original", "setupOpenAppDAMock", "error", "callMyTask", "extractDependenciesMock", "apiSendCommandMock", "commandParams", "mockedCommandResponse", "deviceAction", "internalApi", "TestCommand", "resolve", "reject", "expectedStates", "params"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as D,Right as S}from"purify-ts";import{assign as k,createMachine as I}from"xstate";import{ApduBuilder as M}from"../../../apdu/utils/ApduBuilder";import{CommandResultFactory as A}from"../../../command/model/CommandResult";import{makeDeviceActionInternalApiMock as p}from"../../../device-action/__test-utils__/makeInternalApi";import{testDeviceActionStates as f}from"../../../device-action/__test-utils__/testDeviceActionStates";import{DeviceActionStatus as n}from"../../../device-action/model/DeviceActionState";import{UserInteractionRequired as e}from"../../../device-action/model/UserInteractionRequired";import{UnknownDAError as C}from"../../../device-action/os/Errors";import{OpenAppDeviceAction as g}from"../../../device-action/os/OpenAppDeviceAction/OpenAppDeviceAction";import{UnknownDeviceExchangeError as v}from"../../../../../src";import{SendCommandInAppDeviceAction as c}from"./SendCommandInAppDeviceAction";vi.mock("@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction",async r=>({...await r(),OpenAppDeviceAction:vi.fn(()=>({makeStateMachine:vi.fn()}))}));const u=r=>{g.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>I({initial:"pending",states:{pending:{entry:k({intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp}}),after:{0:"done"}},done:{type:"final"}},output:()=>r?D(r):S(void 0)}))}))};describe("SendCommandInAppDeviceAction",()=>{const r=vi.fn(),i=()=>({sendCommand:r}),{sendCommand:y}=p(),m={paramString:"aParameter",paramNumber:1234},l={aNumber:5678,aString:"mockedResponseString"};beforeEach(()=>{vi.resetAllMocks()}),describe("without mocking extractDependencies",()=>{it("should call sendCommand on internalApi with the correct parameters",async()=>{u(),y.mockResolvedValue(A({data:void 0}));const o=new c({input:{command:new d(m),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}});await new Promise((a,t)=>{o._execute(p()).observable.subscribe({error:()=>t(),complete:()=>a(),next:()=>{}})}),expect(y).toHaveBeenCalledWith(new d(m))})}),describe("error cases",()=>{it("should error and output the error if the open app fails",()=>new Promise((o,a)=>{u(new C("Mocked error"));const t=[{status:n.Pending,intermediateValue:{requiredUserInteraction:e.None}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp}},{status:n.Error,error:new C("Mocked error")}];f(new c({input:{command:new d(m),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}}),t,p(),{onDone:o,onError:a})})),it("should error and output an error if the send command fails",()=>new Promise((o,a)=>{u(),r.mockResolvedValue(A({error:new v("Mocked error")}));const t=new c({input:{command:new d(m),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}});vi.spyOn(t,"extractDependencies").mockImplementation(i);const s=[{status:n.Pending,intermediateValue:{requiredUserInteraction:e.None}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.VerifyAddress}},{status:n.Error,error:new v("Mocked error")}];f(t,s,p(),{onDone:o,onError:a})}))}),describe("success cases",()=>{it("should succeed and output the command result if the send command succeeds",()=>new Promise((o,a)=>{u(),r.mockResolvedValue(A({data:l}));const t=new c({input:{command:new d(m),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}});vi.spyOn(t,"extractDependencies").mockImplementation(i);const s=[{status:n.Pending,intermediateValue:{requiredUserInteraction:e.None}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.VerifyAddress}},{status:n.Completed,output:l}];f(t,s,p(),{onDone:o,onError:a})})),it("should succeed while skipping OpenApp",()=>new Promise((o,a)=>{u(),r.mockResolvedValue(A({data:l}));const t=new c({input:{command:new d(m),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!0}});vi.spyOn(t,"extractDependencies").mockImplementation(i);const s=[{status:n.Pending,intermediateValue:{requiredUserInteraction:e.VerifyAddress}},{status:n.Completed,output:l}];f(t,s,p(),{onDone:o,onError:a})}))})});class d{params;constructor(i){this.params=i}getApdu(){return new M({cla:0,ins:1,p1:2,p2:3}).add32BitUIntToData(this.params.paramNumber).addAsciiStringToData(this.params.paramString).build()}parseResponse(){return A({data:{aNumber:1,aString:"aString"}})}}
1
+ import{Left as D,Right as S}from"purify-ts";import{assign as k,createMachine as I}from"xstate";import{ApduBuilder as M}from"../../../apdu/utils/ApduBuilder";import{CommandResultFactory as A}from"../../../command/model/CommandResult";import{makeDeviceActionInternalApiMock as d}from"../../../device-action/__test-utils__/makeInternalApi";import{testDeviceActionStates as f}from"../../../device-action/__test-utils__/testDeviceActionStates";import{DeviceActionStatus as n}from"../../../device-action/model/DeviceActionState";import{UserInteractionRequired as e}from"../../../device-action/model/UserInteractionRequired";import{UnknownDAError as C}from"../../../device-action/os/Errors";import{OpenAppDeviceAction as g}from"../../../device-action/os/OpenAppDeviceAction/OpenAppDeviceAction";import{UnknownDeviceExchangeError as v}from"../../../../../src";import{SendCommandInAppDeviceAction as c}from"./SendCommandInAppDeviceAction";vi.mock("@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction",async r=>({...await r(),OpenAppDeviceAction:vi.fn(()=>({makeStateMachine:vi.fn()}))}));const u=r=>{g.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>I({initial:"pending",states:{pending:{entry:k({intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp}}),after:{0:"done"}},done:{type:"final"}},output:()=>r?D(r):S(void 0)}))}))};describe("SendCommandInAppDeviceAction",()=>{const r=vi.fn(),i=()=>({sendCommand:r}),{sendCommand:y}=d(),m={paramString:"aParameter",paramNumber:1234},l={aNumber:5678,aString:"mockedResponseString"};beforeEach(()=>{vi.resetAllMocks()}),describe("without mocking extractDependencies",()=>{it("should call sendCommand on internalApi with the correct parameters",async()=>{u(),y.mockResolvedValue(A({data:void 0}));const o=new c({input:{command:new p(m),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}});await new Promise((a,t)=>{o._execute(d()).observable.subscribe({error:()=>t(),complete:()=>a(),next:()=>{}})}),expect(y).toHaveBeenCalledWith(new p(m))})}),describe("error cases",()=>{it("should error and output the error if the open app fails",()=>new Promise((o,a)=>{u(new C("Mocked error"));const t=[{status:n.Pending,intermediateValue:{requiredUserInteraction:e.None}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp}},{status:n.Error,error:new C("Mocked error")}];f(new c({input:{command:new p(m),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}}),t,d(),{onDone:o,onError:a})})),it("should error and output an error if the send command fails",()=>new Promise((o,a)=>{u(),r.mockResolvedValue(A({error:new v("Mocked error")}));const t=new c({input:{command:new p(m),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}});vi.spyOn(t,"extractDependencies").mockImplementation(i);const s=[{status:n.Pending,intermediateValue:{requiredUserInteraction:e.None}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.VerifyAddress}},{status:n.Error,error:new v("Mocked error")}];f(t,s,d(),{onDone:o,onError:a})}))}),describe("success cases",()=>{it("should succeed and output the command result if the send command succeeds",()=>new Promise((o,a)=>{u(),r.mockResolvedValue(A({data:l}));const t=new c({input:{command:new p(m),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}});vi.spyOn(t,"extractDependencies").mockImplementation(i);const s=[{status:n.Pending,intermediateValue:{requiredUserInteraction:e.None}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.VerifyAddress}},{status:n.Completed,output:l}];f(t,s,d(),{onDone:o,onError:a})})),it("should succeed while skipping OpenApp",()=>new Promise((o,a)=>{u(),r.mockResolvedValue(A({data:l}));const t=new c({input:{command:new p(m),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!0}});vi.spyOn(t,"extractDependencies").mockImplementation(i);const s=[{status:n.Pending,intermediateValue:{requiredUserInteraction:e.VerifyAddress}},{status:n.Completed,output:l}];f(t,s,d(),{onDone:o,onError:a})}))})});class p{name="testCommand";params;constructor(i){this.params=i}getApdu(){return new M({cla:0,ins:1,p1:2,p2:3}).add32BitUIntToData(this.params.paramNumber).addAsciiStringToData(this.params.paramString).build()}parseResponse(){return A({data:{aNumber:1,aString:"aString"}})}}
2
2
  //# sourceMappingURL=SendCommandInAppDeviceAction.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.ts"],
4
- "sourcesContent": ["/* eslint @typescript-eslint/consistent-type-imports:0 */\nimport { Left, Right } from \"purify-ts\";\nimport { type Mock } from \"vitest\";\nimport { assign, createMachine } from \"xstate\";\n\nimport { type Apdu } from \"@api/apdu/model/Apdu\";\nimport { ApduBuilder } from \"@api/apdu/utils/ApduBuilder\";\nimport { CommandResultFactory } from \"@api/command/model/CommandResult\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { testDeviceActionStates } from \"@api/device-action/__test-utils__/testDeviceActionStates\";\nimport {\n type DeviceActionState,\n DeviceActionStatus,\n} from \"@api/device-action/model/DeviceActionState\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { type Command } from \"@api/types\";\nimport { UnknownDeviceExchangeError } from \"@root/src\";\n\nimport { SendCommandInAppDeviceAction } from \"./SendCommandInAppDeviceAction\";\nimport {\n type SendCommandInAppDAError,\n type SendCommandInAppDAIntermediateValue,\n type SendCommandInAppDAOutput,\n} from \"./SendCommandInAppDeviceActionTypes\";\n\nvi.mock(\n \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\",\n async (importOriginal) => {\n const original =\n await importOriginal<\n typeof import(\"../OpenAppDeviceAction/OpenAppDeviceAction\")\n >();\n\n return {\n ...original,\n OpenAppDeviceAction: vi.fn(() => ({\n makeStateMachine: vi.fn(),\n })),\n };\n },\n);\n\nconst setupOpenAppDAMock = (error?: unknown) => {\n (OpenAppDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n initial: \"pending\",\n states: {\n pending: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n }),\n after: {\n 0: \"done\",\n },\n },\n done: {\n type: \"final\",\n },\n },\n output: () => (error ? Left(error) : Right(undefined)),\n }),\n ),\n }));\n};\n\ndescribe(\"SendCommandInAppDeviceAction\", () => {\n const sendMyCommand = vi.fn();\n\n const extractDependenciesMock = () => ({\n sendCommand: sendMyCommand,\n });\n\n const { sendCommand: apiSendCommandMock } = makeDeviceActionInternalApiMock();\n\n const commandParams = {\n paramString: \"aParameter\",\n paramNumber: 1234,\n };\n const mockedCommandResponse = {\n aNumber: 5678,\n aString: \"mockedResponseString\",\n };\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"without mocking extractDependencies\", () => {\n it(\"should call sendCommand on internalApi with the correct parameters\", async () => {\n setupOpenAppDAMock();\n apiSendCommandMock.mockResolvedValue(\n CommandResultFactory({ data: undefined }),\n );\n\n const deviceAction = new SendCommandInAppDeviceAction({\n input: {\n command: new TestCommand(commandParams),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n await new Promise<void>((resolve, reject) => {\n deviceAction\n ._execute(makeDeviceActionInternalApiMock())\n .observable.subscribe({\n error: () => reject(),\n complete: () => resolve(),\n next: () => {},\n });\n });\n\n expect(apiSendCommandMock).toHaveBeenCalledWith(\n new TestCommand(commandParams),\n );\n });\n });\n\n describe(\"error cases\", () => {\n it(\"should error and output the error if the open app fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock(new UnknownDAError(\"Mocked error\"));\n\n const expectedStates: MyCommandSendCommandDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"Mocked error\"),\n },\n ];\n\n testDeviceActionStates(\n new SendCommandInAppDeviceAction({\n input: {\n command: new TestCommand(commandParams),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n }),\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should error and output an error if the send command fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n sendMyCommand.mockResolvedValue(\n CommandResultFactory({\n error: new UnknownDeviceExchangeError(\"Mocked error\"),\n }),\n );\n\n const deviceAction = new SendCommandInAppDeviceAction({\n input: {\n command: new TestCommand(commandParams),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandSendCommandDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDeviceExchangeError(\"Mocked error\"),\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"success cases\", () => {\n it(\"should succeed and output the command result if the send command succeeds\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n sendMyCommand.mockResolvedValue(\n CommandResultFactory({ data: mockedCommandResponse }),\n );\n\n const deviceAction = new SendCommandInAppDeviceAction({\n input: {\n command: new TestCommand(commandParams),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandSendCommandDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Completed,\n output: mockedCommandResponse,\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should succeed while skipping OpenApp\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n sendMyCommand.mockResolvedValue(\n CommandResultFactory({ data: mockedCommandResponse }),\n );\n\n const deviceAction = new SendCommandInAppDeviceAction({\n input: {\n command: new TestCommand(commandParams),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: true,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandSendCommandDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Completed,\n output: mockedCommandResponse,\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n});\n\ntype MyCommandResponse = {\n aNumber: number;\n aString: string;\n};\n\ntype MyCommandParams = {\n paramString: string;\n paramNumber: number;\n};\n\nclass TestCommand implements Command<MyCommandResponse, MyCommandParams> {\n params: MyCommandParams;\n constructor(params: MyCommandParams) {\n this.params = params;\n }\n getApdu(): Apdu {\n return new ApduBuilder({ cla: 0x00, ins: 0x01, p1: 0x02, p2: 0x03 })\n .add32BitUIntToData(this.params.paramNumber)\n .addAsciiStringToData(this.params.paramString)\n .build();\n }\n parseResponse() {\n return CommandResultFactory({ data: { aNumber: 1, aString: \"aString\" } });\n }\n}\n\ntype MyCommandSendCommandDAState = DeviceActionState<\n SendCommandInAppDAOutput<MyCommandResponse>,\n SendCommandInAppDAError<UnknownDAError>,\n SendCommandInAppDAIntermediateValue<\n UserInteractionRequired.None | UserInteractionRequired.VerifyAddress\n >\n>;\n"],
5
- "mappings": "AACA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,UAAAC,EAAQ,iBAAAC,MAAqB,SAGtC,OAAS,eAAAC,MAAmB,8BAC5B,OAAS,wBAAAC,MAA4B,mCACrC,OAAS,mCAAAC,MAAuC,oDAChD,OAAS,0BAAAC,MAA8B,2DACvC,OAEE,sBAAAC,MACK,6CACP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,kBAAAC,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AAIU,EAAYH,CAAa,EACtC,QAAS,QACT,wBAAyBX,EAAwB,cACjD,YAAa,EACf,CACF,CAAC,EAED,GAAG,MAAMa,EAAc,qBAAqB,EAAE,mBAC5CJ,CACF,EAEA,MAAMQ,EAAgD,CACpD,CACE,OAAQlB,EAAmB,QAC3B,kBAAmB,CACjB,wBAAyBC,EAAwB,aACnD,CACF,EACA,CACE,OAAQD,EAAmB,UAC3B,OAAQa,CACV,CACF,EAEAd,EACEe,EACAI,EACApB,EAAgC,EAChC,CACE,OAAQkB,EACR,QAASC,CACX,CACF,CACF,CAAC,CAAC,CACN,CAAC,CACH,CAAC,EAYD,MAAMF,CAAmE,CACvE,OACA,YAAYI,EAAyB,CACnC,KAAK,OAASA,CAChB,CACA,SAAgB,CACd,OAAO,IAAIvB,EAAY,CAAE,IAAK,EAAM,IAAK,EAAM,GAAI,EAAM,GAAI,CAAK,CAAC,EAChE,mBAAmB,KAAK,OAAO,WAAW,EAC1C,qBAAqB,KAAK,OAAO,WAAW,EAC5C,MAAM,CACX,CACA,eAAgB,CACd,OAAOC,EAAqB,CAAE,KAAM,CAAE,QAAS,EAAG,QAAS,SAAU,CAAE,CAAC,CAC1E,CACF",
4
+ "sourcesContent": ["/* eslint @typescript-eslint/consistent-type-imports:0 */\nimport { Left, Right } from \"purify-ts\";\nimport { type Mock } from \"vitest\";\nimport { assign, createMachine } from \"xstate\";\n\nimport { type Apdu } from \"@api/apdu/model/Apdu\";\nimport { ApduBuilder } from \"@api/apdu/utils/ApduBuilder\";\nimport { CommandResultFactory } from \"@api/command/model/CommandResult\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { testDeviceActionStates } from \"@api/device-action/__test-utils__/testDeviceActionStates\";\nimport {\n type DeviceActionState,\n DeviceActionStatus,\n} from \"@api/device-action/model/DeviceActionState\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { type Command } from \"@api/types\";\nimport { UnknownDeviceExchangeError } from \"@root/src\";\n\nimport { SendCommandInAppDeviceAction } from \"./SendCommandInAppDeviceAction\";\nimport {\n type SendCommandInAppDAError,\n type SendCommandInAppDAIntermediateValue,\n type SendCommandInAppDAOutput,\n} from \"./SendCommandInAppDeviceActionTypes\";\n\nvi.mock(\n \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\",\n async (importOriginal) => {\n const original =\n await importOriginal<\n typeof import(\"../OpenAppDeviceAction/OpenAppDeviceAction\")\n >();\n\n return {\n ...original,\n OpenAppDeviceAction: vi.fn(() => ({\n makeStateMachine: vi.fn(),\n })),\n };\n },\n);\n\nconst setupOpenAppDAMock = (error?: unknown) => {\n (OpenAppDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n initial: \"pending\",\n states: {\n pending: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n }),\n after: {\n 0: \"done\",\n },\n },\n done: {\n type: \"final\",\n },\n },\n output: () => (error ? Left(error) : Right(undefined)),\n }),\n ),\n }));\n};\n\ndescribe(\"SendCommandInAppDeviceAction\", () => {\n const sendMyCommand = vi.fn();\n\n const extractDependenciesMock = () => ({\n sendCommand: sendMyCommand,\n });\n\n const { sendCommand: apiSendCommandMock } = makeDeviceActionInternalApiMock();\n\n const commandParams = {\n paramString: \"aParameter\",\n paramNumber: 1234,\n };\n const mockedCommandResponse = {\n aNumber: 5678,\n aString: \"mockedResponseString\",\n };\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"without mocking extractDependencies\", () => {\n it(\"should call sendCommand on internalApi with the correct parameters\", async () => {\n setupOpenAppDAMock();\n apiSendCommandMock.mockResolvedValue(\n CommandResultFactory({ data: undefined }),\n );\n\n const deviceAction = new SendCommandInAppDeviceAction({\n input: {\n command: new TestCommand(commandParams),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n await new Promise<void>((resolve, reject) => {\n deviceAction\n ._execute(makeDeviceActionInternalApiMock())\n .observable.subscribe({\n error: () => reject(),\n complete: () => resolve(),\n next: () => {},\n });\n });\n\n expect(apiSendCommandMock).toHaveBeenCalledWith(\n new TestCommand(commandParams),\n );\n });\n });\n\n describe(\"error cases\", () => {\n it(\"should error and output the error if the open app fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock(new UnknownDAError(\"Mocked error\"));\n\n const expectedStates: MyCommandSendCommandDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"Mocked error\"),\n },\n ];\n\n testDeviceActionStates(\n new SendCommandInAppDeviceAction({\n input: {\n command: new TestCommand(commandParams),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n }),\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should error and output an error if the send command fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n sendMyCommand.mockResolvedValue(\n CommandResultFactory({\n error: new UnknownDeviceExchangeError(\"Mocked error\"),\n }),\n );\n\n const deviceAction = new SendCommandInAppDeviceAction({\n input: {\n command: new TestCommand(commandParams),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandSendCommandDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDeviceExchangeError(\"Mocked error\"),\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"success cases\", () => {\n it(\"should succeed and output the command result if the send command succeeds\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n sendMyCommand.mockResolvedValue(\n CommandResultFactory({ data: mockedCommandResponse }),\n );\n\n const deviceAction = new SendCommandInAppDeviceAction({\n input: {\n command: new TestCommand(commandParams),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandSendCommandDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Completed,\n output: mockedCommandResponse,\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should succeed while skipping OpenApp\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n sendMyCommand.mockResolvedValue(\n CommandResultFactory({ data: mockedCommandResponse }),\n );\n\n const deviceAction = new SendCommandInAppDeviceAction({\n input: {\n command: new TestCommand(commandParams),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: true,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandSendCommandDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Completed,\n output: mockedCommandResponse,\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n});\n\ntype MyCommandResponse = {\n aNumber: number;\n aString: string;\n};\n\ntype MyCommandParams = {\n paramString: string;\n paramNumber: number;\n};\n\nclass TestCommand implements Command<MyCommandResponse, MyCommandParams> {\n readonly name = \"testCommand\";\n\n params: MyCommandParams;\n constructor(params: MyCommandParams) {\n this.params = params;\n }\n getApdu(): Apdu {\n return new ApduBuilder({ cla: 0x00, ins: 0x01, p1: 0x02, p2: 0x03 })\n .add32BitUIntToData(this.params.paramNumber)\n .addAsciiStringToData(this.params.paramString)\n .build();\n }\n parseResponse() {\n return CommandResultFactory({ data: { aNumber: 1, aString: \"aString\" } });\n }\n}\n\ntype MyCommandSendCommandDAState = DeviceActionState<\n SendCommandInAppDAOutput<MyCommandResponse>,\n SendCommandInAppDAError<UnknownDAError>,\n SendCommandInAppDAIntermediateValue<\n UserInteractionRequired.None | UserInteractionRequired.VerifyAddress\n >\n>;\n"],
5
+ "mappings": "AACA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,UAAAC,EAAQ,iBAAAC,MAAqB,SAGtC,OAAS,eAAAC,MAAmB,8BAC5B,OAAS,wBAAAC,MAA4B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ACrCV,EAAmB,EAEnBE,EAAc,kBACZZ,EAAqB,CAAE,KAAMgB,CAAsB,CAAC,CACtD,EAEA,MAAMC,EAAe,IAAIT,EAA6B,CACpD,MAAO,CACL,QAAS,IAAIU,EAAYH,CAAa,EACtC,QAAS,QACT,wBAAyBX,EAAwB,cACjD,YAAa,EACf,CACF,CAAC,EAED,GAAG,MAAMa,EAAc,qBAAqB,EAAE,mBAC5CJ,CACF,EAEA,MAAMQ,EAAgD,CACpD,CACE,OAAQlB,EAAmB,QAC3B,kBAAmB,CACjB,wBAAyBC,EAAwB,aACnD,CACF,EACA,CACE,OAAQD,EAAmB,UAC3B,OAAQa,CACV,CACF,EAEAd,EACEe,EACAI,EACApB,EAAgC,EAChC,CACE,OAAQkB,EACR,QAASC,CACX,CACF,CACF,CAAC,CAAC,CACN,CAAC,CACH,CAAC,EAYD,MAAMF,CAAmE,CAC9D,KAAO,cAEhB,OACA,YAAYI,EAAyB,CACnC,KAAK,OAASA,CAChB,CACA,SAAgB,CACd,OAAO,IAAIvB,EAAY,CAAE,IAAK,EAAM,IAAK,EAAM,GAAI,EAAM,GAAI,CAAK,CAAC,EAChE,mBAAmB,KAAK,OAAO,WAAW,EAC1C,qBAAqB,KAAK,OAAO,WAAW,EAC5C,MAAM,CACX,CACA,eAAgB,CACd,OAAOC,EAAqB,CAAE,KAAM,CAAE,QAAS,EAAG,QAAS,SAAU,CAAE,CAAC,CAC1E,CACF",
6
6
  "names": ["Left", "Right", "assign", "createMachine", "ApduBuilder", "CommandResultFactory", "makeDeviceActionInternalApiMock", "testDeviceActionStates", "DeviceActionStatus", "UserInteractionRequired", "UnknownDAError", "OpenAppDeviceAction", "UnknownDeviceExchangeError", "SendCommandInAppDeviceAction", "importOriginal", "setupOpenAppDAMock", "error", "sendMyCommand", "extractDependenciesMock", "apiSendCommandMock", "commandParams", "mockedCommandResponse", "deviceAction", "TestCommand", "resolve", "reject", "expectedStates", "params"]
7
7
  }
@@ -1,2 +1,2 @@
1
- class c{id;sessionId;modelId;name;type;constructor({transportConnectedDevice:{id:e,deviceModel:{id:o,productName:n},type:i},sessionId:t}){this.id=e,this.sessionId=t,this.modelId=o,this.name=n,this.type=i}}export{c as ConnectedDevice};
1
+ class s{id;sessionId;modelId;name;type;transport;constructor({transportConnectedDevice:{id:e,deviceModel:{id:o,productName:t},type:n,transport:i},sessionId:r}){this.id=e,this.sessionId=r,this.modelId=o,this.name=t,this.type=n,this.transport=i}}export{s as ConnectedDevice};
2
2
  //# sourceMappingURL=ConnectedDevice.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/transport/model/ConnectedDevice.ts"],
4
- "sourcesContent": ["import { type DeviceId, type DeviceModelId } from \"@api/device/DeviceModel\";\nimport { type ConnectionType } from \"@api/discovery/ConnectionType\";\nimport { type TransportConnectedDevice } from \"@api/transport/model/TransportConnectedDevice\";\nimport { type DeviceSessionId } from \"@api/types\";\n\ntype ConnectedDeviceConstructorArgs = {\n readonly sessionId: DeviceSessionId;\n readonly transportConnectedDevice: TransportConnectedDevice;\n};\n\nexport class ConnectedDevice {\n public readonly id: DeviceId;\n public readonly sessionId: DeviceSessionId;\n public readonly modelId: DeviceModelId;\n public readonly name: string;\n public readonly type: ConnectionType;\n\n constructor({\n transportConnectedDevice: {\n id,\n deviceModel: { id: deviceModelId, productName: deviceName },\n type,\n },\n sessionId,\n }: ConnectedDeviceConstructorArgs) {\n this.id = id;\n this.sessionId = sessionId;\n this.modelId = deviceModelId;\n this.name = deviceName;\n this.type = type;\n }\n}\n"],
5
- "mappings": "AAUO,MAAMA,CAAgB,CACX,GACA,UACA,QACA,KACA,KAEhB,YAAY,CACV,yBAA0B,CACxB,GAAAC,EACA,YAAa,CAAE,GAAIC,EAAe,YAAaC,CAAW,EAC1D,KAAAC,CACF,EACA,UAAAC,CACF,EAAmC,CACjC,KAAK,GAAKJ,EACV,KAAK,UAAYI,EACjB,KAAK,QAAUH,EACf,KAAK,KAAOC,EACZ,KAAK,KAAOC,CACd,CACF",
6
- "names": ["ConnectedDevice", "id", "deviceModelId", "deviceName", "type", "sessionId"]
4
+ "sourcesContent": ["import { type DeviceId, type DeviceModelId } from \"@api/device/DeviceModel\";\nimport { type ConnectionType } from \"@api/discovery/ConnectionType\";\nimport { type TransportConnectedDevice } from \"@api/transport/model/TransportConnectedDevice\";\nimport { type DeviceSessionId, type TransportIdentifier } from \"@api/types\";\n\ntype ConnectedDeviceConstructorArgs = {\n readonly sessionId: DeviceSessionId;\n readonly transportConnectedDevice: TransportConnectedDevice;\n};\n\nexport class ConnectedDevice {\n public readonly id: DeviceId;\n public readonly sessionId: DeviceSessionId;\n public readonly modelId: DeviceModelId;\n public readonly name: string;\n public readonly type: ConnectionType;\n public readonly transport: TransportIdentifier;\n\n constructor({\n transportConnectedDevice: {\n id,\n deviceModel: { id: deviceModelId, productName: deviceName },\n type,\n transport,\n },\n sessionId,\n }: ConnectedDeviceConstructorArgs) {\n this.id = id;\n this.sessionId = sessionId;\n this.modelId = deviceModelId;\n this.name = deviceName;\n this.type = type;\n this.transport = transport;\n }\n}\n"],
5
+ "mappings": "AAUO,MAAMA,CAAgB,CACX,GACA,UACA,QACA,KACA,KACA,UAEhB,YAAY,CACV,yBAA0B,CACxB,GAAAC,EACA,YAAa,CAAE,GAAIC,EAAe,YAAaC,CAAW,EAC1D,KAAAC,EACA,UAAAC,CACF,EACA,UAAAC,CACF,EAAmC,CACjC,KAAK,GAAKL,EACV,KAAK,UAAYK,EACjB,KAAK,QAAUJ,EACf,KAAK,KAAOC,EACZ,KAAK,KAAOC,EACZ,KAAK,UAAYC,CACnB,CACF",
6
+ "names": ["ConnectedDevice", "id", "deviceModelId", "deviceName", "type", "transport", "sessionId"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{BehaviorSubject as d}from"rxjs";import{v4 as h}from"uuid";import{CommandUtils as S}from"../../../api/command/utils/CommandUtils";import{DeviceStatus as a}from"../../../api/device/DeviceStatus";import{DeviceSessionStateType as u}from"../../../api/device-session/DeviceSessionState";import{bufferToHexaString as c}from"../../../api/index";import{DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS as m}from"../../device-session/data/DeviceSessionRefresherConst";import{MutexService as D}from"../../device-session/service/MutexService";import{RefresherService as l}from"../../device-session/service/RefresherService";import{DevicePinger as _}from"./DevicePinger";import{DeviceSessionEventDispatcher as f,SessionEvents as n}from"./DeviceSessionEventDispatcher";import{DeviceSessionRefresher as g}from"./DeviceSessionRefresher";import{DeviceSessionStateHandler as E}from"./DeviceSessionStateHandler";class L{_id;_connectedDevice;_deviceState;_managerApiService;_secureChannelService;_logger;_refresherOptions;_pinger;_deviceSessionRefresher;_refresherService;_commandMutex=new D;_sessionEventDispatcher=new f;constructor({connectedDevice:e,id:r=h()},t,i,s,v){this._id=r,this._connectedDevice=e,this._logger=t("device-session"),this._managerApiService=i,this._secureChannelService=s,this._refresherOptions={...m,...v},this._deviceState=new d({sessionStateType:u.Connected,deviceStatus:a.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id}),this._pinger=new _(t,e,this._sessionEventDispatcher,(o,p)=>this.sendCommand(o,p)),this._deviceSessionRefresher=new g(t,this._refresherOptions,this._sessionEventDispatcher,this._connectedDevice),new E(t,this._sessionEventDispatcher,this._connectedDevice,this._deviceState,o=>this.setDeviceSessionState(o)),this._refresherService=new l(t,{start:()=>this._deviceSessionRefresher.restartRefresher(),stop:()=>this._deviceSessionRefresher.stopRefresher()})}async initialiseSession(){try{await this._pinger.ping()}catch(e){throw this._logger.error("Error while initialising session",{data:{error:e}}),e}finally{this._refresherOptions.isRefresherDisabled||this._deviceSessionRefresher.startRefresher()}}get id(){return this._id}get connectedDevice(){return this._connectedDevice}get state(){return this._deviceState.asObservable()}getDeviceSessionState(){return this._deviceState.getValue()}setDeviceSessionState(e){this._deviceState.next(e)}async sendApdu(e,r={isPolling:!1,triggersDisconnection:!1,abortTimeout:void 0}){const t=await this._commandMutex.lock();try{this._sessionEventDispatcher.dispatch({eventName:n.DEVICE_STATE_UPDATE_BUSY}),this._logger.debug(`[exchange] => ${c(e,!1)}`);const i=await this._connectedDevice.sendApdu(e,r.triggersDisconnection,r.abortTimeout);return i.ifRight(s=>{this._logger.debug(`[exchange] <= ${c(s.data,!1)}${c(s.statusCode,!1)}`),S.isLockedDeviceResponse(s)?this._sessionEventDispatcher.dispatch({eventName:n.DEVICE_STATE_UPDATE_LOCKED}):this._sessionEventDispatcher.dispatch({eventName:n.DEVICE_STATE_UPDATE_CONNECTED})}).ifLeft(()=>{this._sessionEventDispatcher.dispatch({eventName:n.DEVICE_STATE_UPDATE_CONNECTED})}),i}finally{t()}}async sendCommand(e,r){const t=e.getApdu();return(await this.sendApdu(t.getRawApdu(),{isPolling:!1,triggersDisconnection:e.triggersDisconnection??!1,abortTimeout:r})).caseOf({Left:s=>{throw s},Right:s=>e.parseResponse(s,this._connectedDevice.deviceModel.id)})}executeDeviceAction(e){const{observable:r,cancel:t}=e._execute({sendApdu:async i=>this.sendApdu(i),sendCommand:async(i,s)=>this.sendCommand(i,s),getDeviceModel:()=>this._connectedDevice.deviceModel,getDeviceSessionState:()=>this._deviceState.getValue(),getDeviceSessionStateObservable:()=>this.state,setDeviceSessionState:i=>(this.setDeviceSessionState(i),this._deviceState.getValue()),disableRefresher:i=>this._refresherService.disableRefresher(i),getManagerApiService:()=>this._managerApiService,getSecureChannelService:()=>this._secureChannelService});return{observable:r,cancel:t}}close(){this._updateDeviceStatus(a.NOT_CONNECTED),this._deviceState.complete(),this._deviceSessionRefresher.stopRefresher()}disableRefresher(e){return this._refresherService.disableRefresher(e)}_updateDeviceStatus(e){const r=this._deviceState.getValue();this._deviceState.next({...r,deviceStatus:e})}}export{L as DeviceSession};
1
+ import{BehaviorSubject as d}from"rxjs";import{v4 as h}from"uuid";import{CommandUtils as S}from"../../../api/command/utils/CommandUtils";import{DeviceStatus as v}from"../../../api/device/DeviceStatus";import{DeviceSessionStateType as u}from"../../../api/device-session/DeviceSessionState";import{bufferToHexaString as a}from"../../../api/index";import{DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS as m}from"../../device-session/data/DeviceSessionRefresherConst";import{MutexService as l}from"../../device-session/service/MutexService";import{RefresherService as D}from"../../device-session/service/RefresherService";import{DevicePinger as _}from"./DevicePinger";import{DeviceSessionEventDispatcher as g,SessionEvents as o}from"./DeviceSessionEventDispatcher";import{DeviceSessionRefresher as f}from"./DeviceSessionRefresher";import{DeviceSessionStateHandler as E}from"./DeviceSessionStateHandler";class L{_id;_connectedDevice;_deviceState;_managerApiService;_secureChannelService;_logger;_refresherOptions;_pinger;_deviceSessionRefresher;_refresherService;_commandMutex=new l;_sessionEventDispatcher=new g;constructor({connectedDevice:e,id:r=h()},s,t,i,n){this._id=r,this._connectedDevice=e,this._logger=s("device-session"),this._managerApiService=t,this._secureChannelService=i,this._refresherOptions={...m,...n},this._deviceState=new d({sessionStateType:u.Connected,deviceStatus:v.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id}),this._pinger=new _(s,e,this._sessionEventDispatcher,(c,p)=>this.sendCommand(c,p)),this._deviceSessionRefresher=new f(s,this._refresherOptions,this._sessionEventDispatcher,this._connectedDevice),new E(s,this._sessionEventDispatcher,this._connectedDevice,this._deviceState,c=>this.setDeviceSessionState(c)),this._refresherService=new D(s,{start:()=>this._deviceSessionRefresher.restartRefresher(),stop:()=>this._deviceSessionRefresher.stopRefresher()})}async initialiseSession(){try{await this._pinger.ping()}catch(e){throw this._logger.error("Error while initialising session",{data:{error:e}}),e}finally{this._refresherOptions.isRefresherDisabled||this._deviceSessionRefresher.startRefresher()}}get id(){return this._id}get connectedDevice(){return this._connectedDevice}get state(){return this._deviceState.asObservable()}getDeviceSessionState(){return this._deviceState.getValue()}setDeviceSessionState(e){this._deviceState.next(e)}async sendApdu(e,r={isPolling:!1,triggersDisconnection:!1,abortTimeout:void 0}){const s=await this._commandMutex.lock();try{this._sessionEventDispatcher.dispatch({eventName:o.DEVICE_STATE_UPDATE_BUSY}),this._logger.debug(`[exchange] => ${a(e,!1)}`);const t=await this._connectedDevice.sendApdu(e,r.triggersDisconnection,r.abortTimeout);return t.ifRight(i=>{this._logger.debug(`[exchange] <= ${a(i.data,!1)}${a(i.statusCode,!1)}`),S.isLockedDeviceResponse(i)?this._sessionEventDispatcher.dispatch({eventName:o.DEVICE_STATE_UPDATE_LOCKED}):this._sessionEventDispatcher.dispatch({eventName:o.DEVICE_STATE_UPDATE_CONNECTED})}).ifLeft(()=>{this._sessionEventDispatcher.dispatch({eventName:o.DEVICE_STATE_UPDATE_CONNECTED})}),t}finally{s()}}async sendCommand(e,r){this._logger.debug(`[sendCommand] ${e.name}`);const s=e.getApdu();return(await this.sendApdu(s.getRawApdu(),{isPolling:!1,triggersDisconnection:e.triggersDisconnection??!1,abortTimeout:r})).caseOf({Left:i=>{throw this._logger.error("[sendCommand] error",{data:{err:i}}),i},Right:i=>{const n=e.parseResponse(i,this._connectedDevice.deviceModel.id);return this._logger.debug("[sendCommand] result",{data:{result:n}}),n}})}executeDeviceAction(e){const{observable:r,cancel:s}=e._execute({sendApdu:async t=>this.sendApdu(t),sendCommand:async(t,i)=>this.sendCommand(t,i),getDeviceModel:()=>this._connectedDevice.deviceModel,getDeviceSessionState:()=>this._deviceState.getValue(),getDeviceSessionStateObservable:()=>this.state,setDeviceSessionState:t=>(this.setDeviceSessionState(t),this._deviceState.getValue()),disableRefresher:t=>this._refresherService.disableRefresher(t),getManagerApiService:()=>this._managerApiService,getSecureChannelService:()=>this._secureChannelService});return{observable:r,cancel:s}}close(){this._updateDeviceStatus(v.NOT_CONNECTED),this._deviceState.complete(),this._deviceSessionRefresher.stopRefresher()}disableRefresher(e){return this._refresherService.disableRefresher(e)}_updateDeviceStatus(e){const r=this._deviceState.getValue();this._deviceState.next({...r,deviceStatus:e})}}export{L as DeviceSession};
2
2
  //# sourceMappingURL=DeviceSession.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/device-session/model/DeviceSession.ts"],
4
- "sourcesContent": ["import { type Either } from \"purify-ts\";\nimport { BehaviorSubject, type Observable } from \"rxjs\";\nimport { v4 as uuidv4 } from \"uuid\";\n\nimport { type Command } from \"@api/command/Command\";\nimport { type CommandResult } from \"@api/command/model/CommandResult\";\nimport { CommandUtils } from \"@api/command/utils/CommandUtils\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport {\n type DeviceAction,\n type DeviceActionIntermediateValue,\n type ExecuteDeviceActionReturnType,\n} from \"@api/device-action/DeviceAction\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\nimport { type DeviceSessionId } from \"@api/device-session/types\";\nimport { type DmkError } from \"@api/Error\";\nimport { bufferToHexaString } from \"@api/index\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { type TransportConnectedDevice } from \"@api/transport/model/TransportConnectedDevice\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { MutexService } from \"@internal/device-session/service/MutexService\";\nimport { RefresherService } from \"@internal/device-session/service/RefresherService\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\n\nimport { DevicePinger } from \"./DevicePinger\";\nimport {\n DeviceSessionEventDispatcher,\n SessionEvents,\n} from \"./DeviceSessionEventDispatcher\";\nimport { DeviceSessionRefresher } from \"./DeviceSessionRefresher\";\nimport { DeviceSessionStateHandler } from \"./DeviceSessionStateHandler\";\n\nexport type SessionConstructorArgs = {\n connectedDevice: TransportConnectedDevice;\n id?: DeviceSessionId;\n};\n\nexport type DeviceSessionRefresherOptions = {\n isRefresherDisabled: boolean;\n pollingInterval?: number;\n};\n\ntype SendApduOptions = {\n isPolling?: boolean;\n triggersDisconnection?: boolean;\n abortTimeout?: number;\n};\n\n/**\n * Represents a session with a device.\n */\nexport class DeviceSession {\n private readonly _id: DeviceSessionId;\n private readonly _connectedDevice: TransportConnectedDevice;\n private readonly _deviceState: BehaviorSubject<DeviceSessionState>;\n private readonly _managerApiService: ManagerApiService;\n private readonly _secureChannelService: SecureChannelService;\n private readonly _logger: LoggerPublisherService;\n private readonly _refresherOptions: DeviceSessionRefresherOptions;\n private _pinger: DevicePinger;\n private _deviceSessionRefresher: DeviceSessionRefresher;\n private readonly _refresherService: RefresherService;\n private _commandMutex = new MutexService();\n private _sessionEventDispatcher = new DeviceSessionEventDispatcher();\n\n constructor(\n { connectedDevice, id = uuidv4() }: SessionConstructorArgs,\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n managerApiService: ManagerApiService,\n secureChannelService: SecureChannelService,\n deviceSessionRefresherOptions: DeviceSessionRefresherOptions | undefined,\n ) {\n this._id = id;\n this._connectedDevice = connectedDevice;\n this._logger = loggerModuleFactory(\"device-session\");\n this._managerApiService = managerApiService;\n this._secureChannelService = secureChannelService;\n this._refresherOptions = {\n ...DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n ...deviceSessionRefresherOptions,\n };\n this._deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\n });\n\n this._pinger = new DevicePinger(\n loggerModuleFactory,\n connectedDevice,\n this._sessionEventDispatcher,\n (command, abortTimeout) => this.sendCommand(command, abortTimeout),\n );\n this._deviceSessionRefresher = new DeviceSessionRefresher(\n loggerModuleFactory,\n this._refresherOptions,\n this._sessionEventDispatcher,\n this._connectedDevice,\n );\n new DeviceSessionStateHandler(\n loggerModuleFactory,\n this._sessionEventDispatcher,\n this._connectedDevice,\n this._deviceState,\n (state) => this.setDeviceSessionState(state),\n );\n\n this._refresherService = new RefresherService(loggerModuleFactory, {\n start: () => this._deviceSessionRefresher.restartRefresher(),\n stop: () => this._deviceSessionRefresher.stopRefresher(),\n });\n }\n\n public async initialiseSession(): Promise<void> {\n try {\n await this._pinger.ping();\n } catch (error) {\n this._logger.error(\"Error while initialising session\", {\n data: { error },\n });\n throw error;\n } finally {\n if (!this._refresherOptions.isRefresherDisabled) {\n this._deviceSessionRefresher.startRefresher();\n }\n }\n }\n\n public get id(): DeviceSessionId {\n return this._id;\n }\n\n public get connectedDevice(): TransportConnectedDevice {\n return this._connectedDevice;\n }\n\n public get state(): Observable<DeviceSessionState> {\n return this._deviceState.asObservable();\n }\n\n public getDeviceSessionState(): DeviceSessionState {\n return this._deviceState.getValue();\n }\n\n public setDeviceSessionState(state: DeviceSessionState): void {\n this._deviceState.next(state);\n }\n\n public async sendApdu(\n rawApdu: Uint8Array,\n options: SendApduOptions = {\n isPolling: false,\n triggersDisconnection: false,\n abortTimeout: undefined,\n },\n ): Promise<Either<DmkError, ApduResponse>> {\n const release = await this._commandMutex.lock();\n\n try {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_BUSY,\n });\n\n this._logger.debug(`[exchange] => ${bufferToHexaString(rawApdu, false)}`);\n const result = await this._connectedDevice.sendApdu(\n rawApdu,\n options.triggersDisconnection,\n options.abortTimeout,\n );\n\n result\n .ifRight((response: ApduResponse) => {\n this._logger.debug(\n `[exchange] <= ${bufferToHexaString(response.data, false)}${bufferToHexaString(response.statusCode, false)}`,\n );\n if (CommandUtils.isLockedDeviceResponse(response)) {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_LOCKED,\n });\n } else {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_CONNECTED,\n });\n }\n })\n .ifLeft(() => {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_CONNECTED,\n });\n });\n return result;\n } finally {\n release();\n }\n }\n\n public async sendCommand<Response, Args, ErrorStatusCodes>(\n command: Command<Response, Args, ErrorStatusCodes>,\n abortTimeout?: number,\n ): Promise<CommandResult<Response, ErrorStatusCodes>> {\n const apdu = command.getApdu();\n\n const response = await this.sendApdu(apdu.getRawApdu(), {\n isPolling: false,\n triggersDisconnection: command.triggersDisconnection ?? false,\n abortTimeout,\n });\n\n return response.caseOf({\n Left: (err) => {\n throw err;\n },\n Right: (r) =>\n command.parseResponse(r, this._connectedDevice.deviceModel.id),\n });\n }\n\n public executeDeviceAction<\n Output,\n Input,\n E extends DmkError,\n IntermediateValue extends DeviceActionIntermediateValue,\n >(\n deviceAction: DeviceAction<Output, Input, E, IntermediateValue>,\n ): ExecuteDeviceActionReturnType<Output, E, IntermediateValue> {\n const { observable, cancel } = deviceAction._execute({\n sendApdu: async (apdu: Uint8Array) => this.sendApdu(apdu),\n sendCommand: async <Response, ErrorStatusCodes, Args>(\n command: Command<Response, ErrorStatusCodes, Args>,\n abortTimeout?: number,\n ) => this.sendCommand(command, abortTimeout),\n getDeviceModel: () => this._connectedDevice.deviceModel,\n getDeviceSessionState: () => this._deviceState.getValue(),\n getDeviceSessionStateObservable: () => this.state,\n setDeviceSessionState: (state: DeviceSessionState) => {\n this.setDeviceSessionState(state);\n return this._deviceState.getValue();\n },\n disableRefresher: (blockerId: string) =>\n this._refresherService.disableRefresher(blockerId),\n getManagerApiService: () => this._managerApiService,\n getSecureChannelService: () => this._secureChannelService,\n });\n return { observable, cancel };\n }\n\n public close(): void {\n this._updateDeviceStatus(DeviceStatus.NOT_CONNECTED);\n this._deviceState.complete();\n this._deviceSessionRefresher.stopRefresher();\n }\n\n public disableRefresher(id: string): () => void {\n return this._refresherService.disableRefresher(id);\n }\n\n private _updateDeviceStatus(deviceStatus: DeviceStatus): void {\n const state = this._deviceState.getValue();\n this._deviceState.next({ ...state, deviceStatus });\n }\n}\n"],
5
- "mappings": "AACA,OAAS,mBAAAA,MAAwC,OACjD,OAAS,MAAMC,MAAc,OAI7B,OAAS,gBAAAC,MAAoB,kC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BehaviorSubject, type Observable } from \"rxjs\";\nimport { v4 as uuidv4 } from \"uuid\";\n\nimport { type Command } from \"@api/command/Command\";\nimport { type CommandResult } from \"@api/command/model/CommandResult\";\nimport { CommandUtils } from \"@api/command/utils/CommandUtils\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport {\n type DeviceAction,\n type DeviceActionIntermediateValue,\n type ExecuteDeviceActionReturnType,\n} from \"@api/device-action/DeviceAction\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\nimport { type DeviceSessionId } from \"@api/device-session/types\";\nimport { type DmkError } from \"@api/Error\";\nimport { bufferToHexaString } from \"@api/index\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { type TransportConnectedDevice } from \"@api/transport/model/TransportConnectedDevice\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { MutexService } from \"@internal/device-session/service/MutexService\";\nimport { RefresherService } from \"@internal/device-session/service/RefresherService\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\n\nimport { DevicePinger } from \"./DevicePinger\";\nimport {\n DeviceSessionEventDispatcher,\n SessionEvents,\n} from \"./DeviceSessionEventDispatcher\";\nimport { DeviceSessionRefresher } from \"./DeviceSessionRefresher\";\nimport { DeviceSessionStateHandler } from \"./DeviceSessionStateHandler\";\n\nexport type SessionConstructorArgs = {\n connectedDevice: TransportConnectedDevice;\n id?: DeviceSessionId;\n};\n\nexport type DeviceSessionRefresherOptions = {\n isRefresherDisabled: boolean;\n pollingInterval?: number;\n};\n\ntype SendApduOptions = {\n isPolling?: boolean;\n triggersDisconnection?: boolean;\n abortTimeout?: number;\n};\n\n/**\n * Represents a session with a device.\n */\nexport class DeviceSession {\n private readonly _id: DeviceSessionId;\n private readonly _connectedDevice: TransportConnectedDevice;\n private readonly _deviceState: BehaviorSubject<DeviceSessionState>;\n private readonly _managerApiService: ManagerApiService;\n private readonly _secureChannelService: SecureChannelService;\n private readonly _logger: LoggerPublisherService;\n private readonly _refresherOptions: DeviceSessionRefresherOptions;\n private _pinger: DevicePinger;\n private _deviceSessionRefresher: DeviceSessionRefresher;\n private readonly _refresherService: RefresherService;\n private _commandMutex = new MutexService();\n private _sessionEventDispatcher = new DeviceSessionEventDispatcher();\n\n constructor(\n { connectedDevice, id = uuidv4() }: SessionConstructorArgs,\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n managerApiService: ManagerApiService,\n secureChannelService: SecureChannelService,\n deviceSessionRefresherOptions: DeviceSessionRefresherOptions | undefined,\n ) {\n this._id = id;\n this._connectedDevice = connectedDevice;\n this._logger = loggerModuleFactory(\"device-session\");\n this._managerApiService = managerApiService;\n this._secureChannelService = secureChannelService;\n this._refresherOptions = {\n ...DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n ...deviceSessionRefresherOptions,\n };\n this._deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\n });\n\n this._pinger = new DevicePinger(\n loggerModuleFactory,\n connectedDevice,\n this._sessionEventDispatcher,\n (command, abortTimeout) => this.sendCommand(command, abortTimeout),\n );\n this._deviceSessionRefresher = new DeviceSessionRefresher(\n loggerModuleFactory,\n this._refresherOptions,\n this._sessionEventDispatcher,\n this._connectedDevice,\n );\n new DeviceSessionStateHandler(\n loggerModuleFactory,\n this._sessionEventDispatcher,\n this._connectedDevice,\n this._deviceState,\n (state) => this.setDeviceSessionState(state),\n );\n\n this._refresherService = new RefresherService(loggerModuleFactory, {\n start: () => this._deviceSessionRefresher.restartRefresher(),\n stop: () => this._deviceSessionRefresher.stopRefresher(),\n });\n }\n\n public async initialiseSession(): Promise<void> {\n try {\n await this._pinger.ping();\n } catch (error) {\n this._logger.error(\"Error while initialising session\", {\n data: { error },\n });\n throw error;\n } finally {\n if (!this._refresherOptions.isRefresherDisabled) {\n this._deviceSessionRefresher.startRefresher();\n }\n }\n }\n\n public get id(): DeviceSessionId {\n return this._id;\n }\n\n public get connectedDevice(): TransportConnectedDevice {\n return this._connectedDevice;\n }\n\n public get state(): Observable<DeviceSessionState> {\n return this._deviceState.asObservable();\n }\n\n public getDeviceSessionState(): DeviceSessionState {\n return this._deviceState.getValue();\n }\n\n public setDeviceSessionState(state: DeviceSessionState): void {\n this._deviceState.next(state);\n }\n\n public async sendApdu(\n rawApdu: Uint8Array,\n options: SendApduOptions = {\n isPolling: false,\n triggersDisconnection: false,\n abortTimeout: undefined,\n },\n ): Promise<Either<DmkError, ApduResponse>> {\n const release = await this._commandMutex.lock();\n\n try {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_BUSY,\n });\n\n this._logger.debug(`[exchange] => ${bufferToHexaString(rawApdu, false)}`);\n const result = await this._connectedDevice.sendApdu(\n rawApdu,\n options.triggersDisconnection,\n options.abortTimeout,\n );\n\n result\n .ifRight((response: ApduResponse) => {\n this._logger.debug(\n `[exchange] <= ${bufferToHexaString(response.data, false)}${bufferToHexaString(response.statusCode, false)}`,\n );\n if (CommandUtils.isLockedDeviceResponse(response)) {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_LOCKED,\n });\n } else {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_CONNECTED,\n });\n }\n })\n .ifLeft(() => {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_CONNECTED,\n });\n });\n return result;\n } finally {\n release();\n }\n }\n\n public async sendCommand<Response, Args, ErrorStatusCodes>(\n command: Command<Response, Args, ErrorStatusCodes>,\n abortTimeout?: number,\n ): Promise<CommandResult<Response, ErrorStatusCodes>> {\n this._logger.debug(`[sendCommand] ${command.name}`);\n const apdu = command.getApdu();\n\n const response = await this.sendApdu(apdu.getRawApdu(), {\n isPolling: false,\n triggersDisconnection: command.triggersDisconnection ?? false,\n abortTimeout,\n });\n\n return response.caseOf({\n Left: (err) => {\n this._logger.error(\"[sendCommand] error\", { data: { err } });\n throw err;\n },\n Right: (r) => {\n const result = command.parseResponse(\n r,\n this._connectedDevice.deviceModel.id,\n );\n this._logger.debug(\"[sendCommand] result\", { data: { result } });\n return result;\n },\n });\n }\n\n public executeDeviceAction<\n Output,\n Input,\n E extends DmkError,\n IntermediateValue extends DeviceActionIntermediateValue,\n >(\n deviceAction: DeviceAction<Output, Input, E, IntermediateValue>,\n ): ExecuteDeviceActionReturnType<Output, E, IntermediateValue> {\n const { observable, cancel } = deviceAction._execute({\n sendApdu: async (apdu: Uint8Array) => this.sendApdu(apdu),\n sendCommand: async <Response, ErrorStatusCodes, Args>(\n command: Command<Response, ErrorStatusCodes, Args>,\n abortTimeout?: number,\n ) => this.sendCommand(command, abortTimeout),\n getDeviceModel: () => this._connectedDevice.deviceModel,\n getDeviceSessionState: () => this._deviceState.getValue(),\n getDeviceSessionStateObservable: () => this.state,\n setDeviceSessionState: (state: DeviceSessionState) => {\n this.setDeviceSessionState(state);\n return this._deviceState.getValue();\n },\n disableRefresher: (blockerId: string) =>\n this._refresherService.disableRefresher(blockerId),\n getManagerApiService: () => this._managerApiService,\n getSecureChannelService: () => this._secureChannelService,\n });\n return { observable, cancel };\n }\n\n public close(): void {\n this._updateDeviceStatus(DeviceStatus.NOT_CONNECTED);\n this._deviceState.complete();\n this._deviceSessionRefresher.stopRefresher();\n }\n\n public disableRefresher(id: string): () => void {\n return this._refresherService.disableRefresher(id);\n }\n\n private _updateDeviceStatus(deviceStatus: DeviceStatus): void {\n const state = this._deviceState.getValue();\n this._deviceState.next({ ...state, deviceStatus });\n }\n}\n"],
5
+ "mappings": "AACA,OAAS,mBAAAA,MAAw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,EAC3B,KAAK,wBAAwB,cAAc,CAC7C,CAEO,iBAAiBa,EAAwB,CAC9C,OAAO,KAAK,kBAAkB,iBAAiBA,CAAE,CACnD,CAEQ,oBAAoBqB,EAAkC,CAC5D,MAAMd,EAAQ,KAAK,aAAa,SAAS,EACzC,KAAK,aAAa,KAAK,CAAE,GAAGA,EAAO,aAAAc,CAAa,CAAC,CACnD,CACF",
6
6
  "names": ["BehaviorSubject", "uuidv4", "CommandUtils", "DeviceStatus", "DeviceSessionStateType", "bufferToHexaString", "DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS", "MutexService", "RefresherService", "DevicePinger", "DeviceSessionEventDispatcher", "SessionEvents", "DeviceSessionRefresher", "DeviceSessionStateHandler", "DeviceSession", "connectedDevice", "id", "loggerModuleFactory", "managerApiService", "secureChannelService", "deviceSessionRefresherOptions", "command", "abortTimeout", "state", "error", "rawApdu", "options", "release", "result", "response", "apdu", "err", "r", "deviceAction", "observable", "cancel", "blockerId", "deviceStatus"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{ContainerModule as i}from"inversify";import{ConnectUseCase as C}from"../../discovery/use-case/ConnectUseCase";import{DisconnectUseCase as c}from"../../discovery/use-case/DisconnectUseCase";import{GetConnectedDeviceUseCase as r}from"../../discovery/use-case/GetConnectedDeviceUseCase";import{ListConnectedDevicesUseCase as n}from"../../discovery/use-case/ListConnectedDevicesUseCase";import{ListenToAvailableDevicesUseCase as U}from"../../discovery/use-case/ListenToAvailableDevicesUseCase";import{ListenToConnectedDeviceUseCase as v}from"../../discovery/use-case/ListenToConnectedDeviceUseCase";import{StartDiscoveringUseCase as m}from"../../discovery/use-case/StartDiscoveringUseCase";import{StopDiscoveringUseCase as D}from"../../discovery/use-case/StopDiscoveringUseCase";import{StubUseCase as t}from"../../../../src/di.stub";import{discoveryTypes as e}from"./discoveryTypes";const P=({stub:a=!1})=>new i(({bind:o,rebindSync:s})=>{o(e.ConnectUseCase).to(C),o(e.DisconnectUseCase).to(c),o(e.StartDiscoveringUseCase).to(m),o(e.StopDiscoveringUseCase).to(D),o(e.GetConnectedDeviceUseCase).to(r),o(e.ListenToAvailableDevicesUseCase).to(U),o(e.ListenToConnectedDeviceUseCase).to(v),o(e.ListConnectedDevicesUseCase).to(n),a&&(s(e.ConnectUseCase).to(t),s(e.DisconnectUseCase).to(t),s(e.StartDiscoveringUseCase).to(t),s(e.StopDiscoveringUseCase).to(t),s(e.GetConnectedDeviceUseCase).to(t),s(e.ListenToAvailableDevicesUseCase).to(t),s(e.ListenToConnectedDeviceUseCase).to(t),s(e.ListConnectedDevicesUseCase).to(t))});export{P as discoveryModuleFactory};
1
+ import{ContainerModule as i}from"inversify";import{ConnectUseCase as C}from"../../discovery/use-case/ConnectUseCase";import{DisconnectUseCase as c}from"../../discovery/use-case/DisconnectUseCase";import{GetConnectedDeviceUseCase as r}from"../../discovery/use-case/GetConnectedDeviceUseCase";import{ListConnectedDevicesUseCase as n}from"../../discovery/use-case/ListConnectedDevicesUseCase";import{ListenToAvailableDevicesUseCase as U}from"../../discovery/use-case/ListenToAvailableDevicesUseCase";import{ListenToConnectedDeviceUseCase as m}from"../../discovery/use-case/ListenToConnectedDeviceUseCase";import{ReconnectUseCase as v}from"../../discovery/use-case/ReconnectUseCase";import{StartDiscoveringUseCase as D}from"../../discovery/use-case/StartDiscoveringUseCase";import{StopDiscoveringUseCase as p}from"../../discovery/use-case/StopDiscoveringUseCase";import{StubUseCase as t}from"../../../../src/di.stub";import{discoveryTypes as e}from"./discoveryTypes";const w=({stub:a=!1})=>new i(({bind:o,rebindSync:s})=>{o(e.ConnectUseCase).to(C),o(e.DisconnectUseCase).to(c),o(e.ReconnectUseCase).to(v),o(e.StartDiscoveringUseCase).to(D),o(e.StopDiscoveringUseCase).to(p),o(e.GetConnectedDeviceUseCase).to(r),o(e.ListenToAvailableDevicesUseCase).to(U),o(e.ListenToConnectedDeviceUseCase).to(m),o(e.ListConnectedDevicesUseCase).to(n),a&&(s(e.ConnectUseCase).to(t),s(e.DisconnectUseCase).to(t),s(e.StartDiscoveringUseCase).to(t),s(e.StopDiscoveringUseCase).to(t),s(e.GetConnectedDeviceUseCase).to(t),s(e.ListenToAvailableDevicesUseCase).to(t),s(e.ListenToConnectedDeviceUseCase).to(t),s(e.ListConnectedDevicesUseCase).to(t))});export{w as discoveryModuleFactory};
2
2
  //# sourceMappingURL=discoveryModule.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/discovery/di/discoveryModule.ts"],
4
- "sourcesContent": ["import { ContainerModule } from \"inversify\";\n\nimport { ConnectUseCase } from \"@internal/discovery/use-case/ConnectUseCase\";\nimport { DisconnectUseCase } from \"@internal/discovery/use-case/DisconnectUseCase\";\nimport { GetConnectedDeviceUseCase } from \"@internal/discovery/use-case/GetConnectedDeviceUseCase\";\nimport { ListConnectedDevicesUseCase } from \"@internal/discovery/use-case/ListConnectedDevicesUseCase\";\nimport { ListenToAvailableDevicesUseCase } from \"@internal/discovery/use-case/ListenToAvailableDevicesUseCase\";\nimport { ListenToConnectedDeviceUseCase } from \"@internal/discovery/use-case/ListenToConnectedDeviceUseCase\";\nimport { StartDiscoveringUseCase } from \"@internal/discovery/use-case/StartDiscoveringUseCase\";\nimport { StopDiscoveringUseCase } from \"@internal/discovery/use-case/StopDiscoveringUseCase\";\nimport { StubUseCase } from \"@root/src/di.stub\";\n\nimport { discoveryTypes } from \"./discoveryTypes\";\n\ntype FactoryProps = {\n stub: boolean;\n};\n\nexport const discoveryModuleFactory = ({ stub = false }: FactoryProps) =>\n new ContainerModule(({ bind, rebindSync }) => {\n bind(discoveryTypes.ConnectUseCase).to(ConnectUseCase);\n bind(discoveryTypes.DisconnectUseCase).to(DisconnectUseCase);\n bind(discoveryTypes.StartDiscoveringUseCase).to(StartDiscoveringUseCase);\n bind(discoveryTypes.StopDiscoveringUseCase).to(StopDiscoveringUseCase);\n bind(discoveryTypes.GetConnectedDeviceUseCase).to(\n GetConnectedDeviceUseCase,\n );\n bind(discoveryTypes.ListenToAvailableDevicesUseCase).to(\n ListenToAvailableDevicesUseCase,\n );\n bind(discoveryTypes.ListenToConnectedDeviceUseCase).to(\n ListenToConnectedDeviceUseCase,\n );\n bind(discoveryTypes.ListConnectedDevicesUseCase).to(\n ListConnectedDevicesUseCase,\n );\n\n if (stub) {\n rebindSync(discoveryTypes.ConnectUseCase).to(StubUseCase);\n rebindSync(discoveryTypes.DisconnectUseCase).to(StubUseCase);\n rebindSync(discoveryTypes.StartDiscoveringUseCase).to(StubUseCase);\n rebindSync(discoveryTypes.StopDiscoveringUseCase).to(StubUseCase);\n rebindSync(discoveryTypes.GetConnectedDeviceUseCase).to(StubUseCase);\n rebindSync(discoveryTypes.ListenToAvailableDevicesUseCase).to(\n StubUseCase,\n );\n rebindSync(discoveryTypes.ListenToConnectedDeviceUseCase).to(StubUseCase);\n rebindSync(discoveryTypes.ListConnectedDevicesUseCase).to(StubUseCase);\n }\n });\n"],
5
- "mappings": "AAAA,OAAS,mBAAAA,MAAuB,YAEhC,OAAS,kBAAAC,MAAsB,8CAC/B,OAAS,qBAAAC,MAAyB,iDAClC,OAAS,6BAAAC,MAAiC,yDAC1C,OAAS,+BAAAC,MAAmC,2DAC5C,OAAS,mCAAAC,MAAuC,+DAChD,OAAS,kCAAAC,MAAsC,8DAC/C,OAAS,2BAAAC,MAA+B,uDACxC,OAAS,0BAAAC,MAA8B,sDACvC,OAAS,eAAAC,MAAmB,oBAE5B,OAAS,kBAAAC,MAAsB,mBAMxB,MAAMC,EAAyB,CAAC,CAAE,KAAAC,EAAO,EAAM,IACpD,IAAIZ,EAAgB,CAAC,CAAE,KAAAa,EAAM,WAAAC,CAAW,IAAM,CAC5CD,EAAKH,EAAe,cAAc,EAAE,GAAGT,CAAc,EACrDY,EAAKH,EAAe,iBAAiB,EAAE,GAAGR,CAAiB,EAC3DW,EAAKH,EAAe,uBAAuB,EAAE,GAAGH,CAAuB,EACvEM,EAAKH,EAAe,sBAAsB,EAAE,GAAGF,CAAsB,EACrEK,EAAKH,EAAe,yBAAyB,EAAE,GAC7CP,CACF,EACAU,EAAKH,EAAe,+BAA+B,EAAE,GACnDL,CACF,EACAQ,EAAKH,EAAe,8BAA8B,EAAE,GAClDJ,CACF,EACAO,EAAKH,EAAe,2BAA2B,EAAE,GAC/CN,CACF,EAEIQ,IACFE,EAAWJ,EAAe,cAAc,EAAE,GAAGD,CAAW,EACxDK,EAAWJ,EAAe,iBAAiB,EAAE,GAAGD,CAAW,EAC3DK,EAAWJ,EAAe,uBAAuB,EAAE,GAAGD,CAAW,EACjEK,EAAWJ,EAAe,sBAAsB,EAAE,GAAGD,CAAW,EAChEK,EAAWJ,EAAe,yBAAyB,EAAE,GAAGD,CAAW,EACnEK,EAAWJ,EAAe,+BAA+B,EAAE,GACzDD,CACF,EACAK,EAAWJ,EAAe,8BAA8B,EAAE,GAAGD,CAAW,EACxEK,EAAWJ,EAAe,2BAA2B,EAAE,GAAGD,CAAW,EAEzE,CAAC",
6
- "names": ["ContainerModule", "ConnectUseCase", "DisconnectUseCase", "GetConnectedDeviceUseCase", "ListConnectedDevicesUseCase", "ListenToAvailableDevicesUseCase", "ListenToConnectedDeviceUseCase", "StartDiscoveringUseCase", "StopDiscoveringUseCase", "StubUseCase", "discoveryTypes", "discoveryModuleFactory", "stub", "bind", "rebindSync"]
4
+ "sourcesContent": ["import { ContainerModule } from \"inversify\";\n\nimport { ConnectUseCase } from \"@internal/discovery/use-case/ConnectUseCase\";\nimport { DisconnectUseCase } from \"@internal/discovery/use-case/DisconnectUseCase\";\nimport { GetConnectedDeviceUseCase } from \"@internal/discovery/use-case/GetConnectedDeviceUseCase\";\nimport { ListConnectedDevicesUseCase } from \"@internal/discovery/use-case/ListConnectedDevicesUseCase\";\nimport { ListenToAvailableDevicesUseCase } from \"@internal/discovery/use-case/ListenToAvailableDevicesUseCase\";\nimport { ListenToConnectedDeviceUseCase } from \"@internal/discovery/use-case/ListenToConnectedDeviceUseCase\";\nimport { ReconnectUseCase } from \"@internal/discovery/use-case/ReconnectUseCase\";\nimport { StartDiscoveringUseCase } from \"@internal/discovery/use-case/StartDiscoveringUseCase\";\nimport { StopDiscoveringUseCase } from \"@internal/discovery/use-case/StopDiscoveringUseCase\";\nimport { StubUseCase } from \"@root/src/di.stub\";\n\nimport { discoveryTypes } from \"./discoveryTypes\";\n\ntype FactoryProps = {\n stub: boolean;\n};\n\nexport const discoveryModuleFactory = ({ stub = false }: FactoryProps) =>\n new ContainerModule(({ bind, rebindSync }) => {\n bind(discoveryTypes.ConnectUseCase).to(ConnectUseCase);\n bind(discoveryTypes.DisconnectUseCase).to(DisconnectUseCase);\n bind(discoveryTypes.ReconnectUseCase).to(ReconnectUseCase);\n bind(discoveryTypes.StartDiscoveringUseCase).to(StartDiscoveringUseCase);\n bind(discoveryTypes.StopDiscoveringUseCase).to(StopDiscoveringUseCase);\n bind(discoveryTypes.GetConnectedDeviceUseCase).to(\n GetConnectedDeviceUseCase,\n );\n bind(discoveryTypes.ListenToAvailableDevicesUseCase).to(\n ListenToAvailableDevicesUseCase,\n );\n bind(discoveryTypes.ListenToConnectedDeviceUseCase).to(\n ListenToConnectedDeviceUseCase,\n );\n bind(discoveryTypes.ListConnectedDevicesUseCase).to(\n ListConnectedDevicesUseCase,\n );\n\n if (stub) {\n rebindSync(discoveryTypes.ConnectUseCase).to(StubUseCase);\n rebindSync(discoveryTypes.DisconnectUseCase).to(StubUseCase);\n rebindSync(discoveryTypes.StartDiscoveringUseCase).to(StubUseCase);\n rebindSync(discoveryTypes.StopDiscoveringUseCase).to(StubUseCase);\n rebindSync(discoveryTypes.GetConnectedDeviceUseCase).to(StubUseCase);\n rebindSync(discoveryTypes.ListenToAvailableDevicesUseCase).to(\n StubUseCase,\n );\n rebindSync(discoveryTypes.ListenToConnectedDeviceUseCase).to(StubUseCase);\n rebindSync(discoveryTypes.ListConnectedDevicesUseCase).to(StubUseCase);\n }\n });\n"],
5
+ "mappings": "AAAA,OAAS,mBAAA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,EACxEK,EAAWJ,EAAe,2BAA2B,EAAE,GAAGD,CAAW,EAEzE,CAAC",
6
+ "names": ["ContainerModule", "ConnectUseCase", "DisconnectUseCase", "GetConnectedDeviceUseCase", "ListConnectedDevicesUseCase", "ListenToAvailableDevicesUseCase", "ListenToConnectedDeviceUseCase", "ReconnectUseCase", "StartDiscoveringUseCase", "StopDiscoveringUseCase", "StubUseCase", "discoveryTypes", "discoveryModuleFactory", "stub", "bind", "rebindSync"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Container as p}from"inversify";import{TransportMock as f}from"../../../api/transport/model/__mocks__/TransportMock";import{deviceModelModuleFactory as l}from"../../device-model/di/deviceModelModule";import{deviceSessionModuleFactory as d}from"../../device-session/di/deviceSessionModule";import{ConnectUseCase as C}from"../../discovery/use-case/ConnectUseCase";import{DisconnectUseCase as v}from"../../discovery/use-case/DisconnectUseCase";import{ListConnectedDevicesUseCase as u}from"../../discovery/use-case/ListConnectedDevicesUseCase";import{ListenToAvailableDevicesUseCase as g}from"../../discovery/use-case/ListenToAvailableDevicesUseCase";import{StartDiscoveringUseCase as U}from"../../discovery/use-case/StartDiscoveringUseCase";import{StopDiscoveringUseCase as y}from"../../discovery/use-case/StopDiscoveringUseCase";import{loggerModuleFactory as D}from"../../logger-publisher/di/loggerModule";import{managerApiModuleFactory as k}from"../../manager-api/di/managerApiModule";import{secureChannelModuleFactory as M}from"../../secure-channel/di/secureChannelModule";import{transportModuleFactory as b}from"../../transport/di/transportModule";import{discoveryModuleFactory as F}from"./discoveryModule";import{discoveryTypes as o}from"./discoveryTypes";describe("discoveryModuleFactory",()=>{let e,t,s;beforeEach(()=>{t=F({stub:!1}),e=new p,s=new f,e.loadSync(t,D(),l({stub:!1}),d(),b({transports:[vi.fn().mockImplementation(()=>s)]}),k({config:{managerApiUrl:"http://fake.url",mockUrl:"http://fake-mock.url"}}),M({config:{webSocketUrl:"http://fake-websocket.url"}}))}),it("should return the device module",()=>{expect(t).toBeDefined()}),it("should return none mocked use cases",()=>{const r=e.get(o.StartDiscoveringUseCase);expect(r).toBeInstanceOf(U);const n=e.get(o.StopDiscoveringUseCase);expect(n).toBeInstanceOf(y);const c=e.get(o.DisconnectUseCase);expect(c).toBeInstanceOf(v);const i=e.get(o.ConnectUseCase);expect(i).toBeInstanceOf(C);const a=e.get(o.ListenToAvailableDevicesUseCase);expect(a).toBeInstanceOf(g);const m=e.get(o.ListConnectedDevicesUseCase);expect(m).toBeInstanceOf(u)})});
1
+ import{Container as f}from"inversify";import{TransportMock as l}from"../../../api/transport/model/__mocks__/TransportMock";import{deviceModelModuleFactory as C}from"../../device-model/di/deviceModelModule";import{deviceSessionModuleFactory as d}from"../../device-session/di/deviceSessionModule";import{ConnectUseCase as U}from"../../discovery/use-case/ConnectUseCase";import{DisconnectUseCase as v}from"../../discovery/use-case/DisconnectUseCase";import{ListConnectedDevicesUseCase as g}from"../../discovery/use-case/ListConnectedDevicesUseCase";import{ListenToAvailableDevicesUseCase as u}from"../../discovery/use-case/ListenToAvailableDevicesUseCase";import{ReconnectUseCase as y}from"../../discovery/use-case/ReconnectUseCase";import{StartDiscoveringUseCase as D}from"../../discovery/use-case/StartDiscoveringUseCase";import{StopDiscoveringUseCase as k}from"../../discovery/use-case/StopDiscoveringUseCase";import{loggerModuleFactory as M}from"../../logger-publisher/di/loggerModule";import{managerApiModuleFactory as b}from"../../manager-api/di/managerApiModule";import{secureChannelModuleFactory as F}from"../../secure-channel/di/secureChannelModule";import{transportModuleFactory as h}from"../../transport/di/transportModule";import{discoveryModuleFactory as x}from"./discoveryModule";import{discoveryTypes as o}from"./discoveryTypes";describe("discoveryModuleFactory",()=>{let e,t,s;beforeEach(()=>{t=x({stub:!1}),e=new f,s=new l,e.loadSync(t,M(),C({stub:!1}),d(),h({transports:[vi.fn().mockImplementation(()=>s)]}),b({config:{managerApiUrl:"http://fake.url",mockUrl:"http://fake-mock.url"}}),F({config:{webSocketUrl:"http://fake-websocket.url"}}))}),it("should return the device module",()=>{expect(t).toBeDefined()}),it("should return none mocked use cases",()=>{const r=e.get(o.StartDiscoveringUseCase);expect(r).toBeInstanceOf(D);const n=e.get(o.StopDiscoveringUseCase);expect(n).toBeInstanceOf(k);const c=e.get(o.DisconnectUseCase);expect(c).toBeInstanceOf(v);const i=e.get(o.ConnectUseCase);expect(i).toBeInstanceOf(U);const a=e.get(o.ListenToAvailableDevicesUseCase);expect(a).toBeInstanceOf(u);const m=e.get(o.ListConnectedDevicesUseCase);expect(m).toBeInstanceOf(g);const p=e.get(o.ReconnectUseCase);expect(p).toBeInstanceOf(y)})});
2
2
  //# sourceMappingURL=discoveryModule.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/discovery/di/discoveryModule.test.ts"],
4
- "sourcesContent": ["import { Container } from \"inversify\";\n\nimport { TransportMock } from \"@api/transport/model/__mocks__/TransportMock\";\nimport { type DmkConfig, type Transport } from \"@api/types\";\nimport { deviceModelModuleFactory } from \"@internal/device-model/di/deviceModelModule\";\nimport { deviceSessionModuleFactory } from \"@internal/device-session/di/deviceSessionModule\";\nimport { ConnectUseCase } from \"@internal/discovery/use-case/ConnectUseCase\";\nimport { DisconnectUseCase } from \"@internal/discovery/use-case/DisconnectUseCase\";\nimport { ListConnectedDevicesUseCase } from \"@internal/discovery/use-case/ListConnectedDevicesUseCase\";\nimport { ListenToAvailableDevicesUseCase } from \"@internal/discovery/use-case/ListenToAvailableDevicesUseCase\";\nimport { StartDiscoveringUseCase } from \"@internal/discovery/use-case/StartDiscoveringUseCase\";\nimport { StopDiscoveringUseCase } from \"@internal/discovery/use-case/StopDiscoveringUseCase\";\nimport { loggerModuleFactory } from \"@internal/logger-publisher/di/loggerModule\";\nimport { managerApiModuleFactory } from \"@internal/manager-api/di/managerApiModule\";\nimport { secureChannelModuleFactory } from \"@internal/secure-channel/di/secureChannelModule\";\nimport { transportModuleFactory } from \"@internal/transport/di/transportModule\";\n\nimport { discoveryModuleFactory } from \"./discoveryModule\";\nimport { discoveryTypes } from \"./discoveryTypes\";\n\ndescribe(\"discoveryModuleFactory\", () => {\n let container: Container;\n let mod: ReturnType<typeof discoveryModuleFactory>;\n let transport: Transport;\n beforeEach(() => {\n mod = discoveryModuleFactory({ stub: false });\n container = new Container();\n transport = new TransportMock();\n\n container.loadSync(\n mod,\n // The following modules are injected into discovery module\n loggerModuleFactory(),\n deviceModelModuleFactory({ stub: false }),\n deviceSessionModuleFactory(),\n transportModuleFactory({\n transports: [vi.fn().mockImplementation(() => transport)],\n }),\n managerApiModuleFactory({\n config: {\n managerApiUrl: \"http://fake.url\",\n mockUrl: \"http://fake-mock.url\",\n } as DmkConfig,\n }),\n secureChannelModuleFactory({\n config: {\n webSocketUrl: \"http://fake-websocket.url\",\n } as DmkConfig,\n }),\n );\n });\n it(\"should return the device module\", () => {\n expect(mod).toBeDefined();\n });\n\n it(\"should return none mocked use cases\", () => {\n const startDiscoveringUseCase = container.get(\n discoveryTypes.StartDiscoveringUseCase,\n );\n expect(startDiscoveringUseCase).toBeInstanceOf(StartDiscoveringUseCase);\n\n const stopDiscoveringUseCase = container.get(\n discoveryTypes.StopDiscoveringUseCase,\n );\n expect(stopDiscoveringUseCase).toBeInstanceOf(StopDiscoveringUseCase);\n\n const disconnectUseCase = container.get(discoveryTypes.DisconnectUseCase);\n expect(disconnectUseCase).toBeInstanceOf(DisconnectUseCase);\n\n const connectUseCase = container.get(discoveryTypes.ConnectUseCase);\n expect(connectUseCase).toBeInstanceOf(ConnectUseCase);\n\n const listenToAvailableDevicesUseCase = container.get(\n discoveryTypes.ListenToAvailableDevicesUseCase,\n );\n expect(listenToAvailableDevicesUseCase).toBeInstanceOf(\n ListenToAvailableDevicesUseCase,\n );\n const listConnectedDevicesUseCase = container.get(\n discoveryTypes.ListConnectedDevicesUseCase,\n );\n expect(listConnectedDevicesUseCase).toBeInstanceOf(\n ListConnectedDevicesUseCase,\n );\n });\n});\n"],
5
- "mappings": "AAAA,OAAS,aAAAA,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AAID,EAAe,iBAAiB,EACxE,OAAOM,CAAiB,EAAE,eAAehB,CAAiB,EAE1D,MAAMiB,EAAiBN,EAAU,IAAID,EAAe,cAAc,EAClE,OAAOO,CAAc,EAAE,eAAelB,CAAc,EAEpD,MAAMmB,EAAkCP,EAAU,IAChDD,EAAe,+BACjB,EACA,OAAOQ,CAA+B,EAAE,eACtChB,CACF,EACA,MAAMiB,EAA8BR,EAAU,IAC5CD,EAAe,2BACjB,EACA,OAAOS,CAA2B,EAAE,eAClClB,CACF,CACF,CAAC,CACH,CAAC",
6
- "names": ["Container", "TransportMock", "deviceModelModuleFactory", "deviceSessionModuleFactory", "ConnectUseCase", "DisconnectUseCase", "ListConnectedDevicesUseCase", "ListenToAvailableDevicesUseCase", "StartDiscoveringUseCase", "StopDiscoveringUseCase", "loggerModuleFactory", "managerApiModuleFactory", "secureChannelModuleFactory", "transportModuleFactory", "discoveryModuleFactory", "discoveryTypes", "container", "mod", "transport", "startDiscoveringUseCase", "stopDiscoveringUseCase", "disconnectUseCase", "connectUseCase", "listenToAvailableDevicesUseCase", "listConnectedDevicesUseCase"]
4
+ "sourcesContent": ["import { Container } from \"inversify\";\n\nimport { TransportMock } from \"@api/transport/model/__mocks__/TransportMock\";\nimport { type DmkConfig, type Transport } from \"@api/types\";\nimport { deviceModelModuleFactory } from \"@internal/device-model/di/deviceModelModule\";\nimport { deviceSessionModuleFactory } from \"@internal/device-session/di/deviceSessionModule\";\nimport { ConnectUseCase } from \"@internal/discovery/use-case/ConnectUseCase\";\nimport { DisconnectUseCase } from \"@internal/discovery/use-case/DisconnectUseCase\";\nimport { ListConnectedDevicesUseCase } from \"@internal/discovery/use-case/ListConnectedDevicesUseCase\";\nimport { ListenToAvailableDevicesUseCase } from \"@internal/discovery/use-case/ListenToAvailableDevicesUseCase\";\nimport { ReconnectUseCase } from \"@internal/discovery/use-case/ReconnectUseCase\";\nimport { StartDiscoveringUseCase } from \"@internal/discovery/use-case/StartDiscoveringUseCase\";\nimport { StopDiscoveringUseCase } from \"@internal/discovery/use-case/StopDiscoveringUseCase\";\nimport { loggerModuleFactory } from \"@internal/logger-publisher/di/loggerModule\";\nimport { managerApiModuleFactory } from \"@internal/manager-api/di/managerApiModule\";\nimport { secureChannelModuleFactory } from \"@internal/secure-channel/di/secureChannelModule\";\nimport { transportModuleFactory } from \"@internal/transport/di/transportModule\";\n\nimport { discoveryModuleFactory } from \"./discoveryModule\";\nimport { discoveryTypes } from \"./discoveryTypes\";\n\ndescribe(\"discoveryModuleFactory\", () => {\n let container: Container;\n let mod: ReturnType<typeof discoveryModuleFactory>;\n let transport: Transport;\n beforeEach(() => {\n mod = discoveryModuleFactory({ stub: false });\n container = new Container();\n transport = new TransportMock();\n\n container.loadSync(\n mod,\n // The following modules are injected into discovery module\n loggerModuleFactory(),\n deviceModelModuleFactory({ stub: false }),\n deviceSessionModuleFactory(),\n transportModuleFactory({\n transports: [vi.fn().mockImplementation(() => transport)],\n }),\n managerApiModuleFactory({\n config: {\n managerApiUrl: \"http://fake.url\",\n mockUrl: \"http://fake-mock.url\",\n } as DmkConfig,\n }),\n secureChannelModuleFactory({\n config: {\n webSocketUrl: \"http://fake-websocket.url\",\n } as DmkConfig,\n }),\n );\n });\n it(\"should return the device module\", () => {\n expect(mod).toBeDefined();\n });\n\n it(\"should return none mocked use cases\", () => {\n const startDiscoveringUseCase = container.get(\n discoveryTypes.StartDiscoveringUseCase,\n );\n expect(startDiscoveringUseCase).toBeInstanceOf(StartDiscoveringUseCase);\n\n const stopDiscoveringUseCase = container.get(\n discoveryTypes.StopDiscoveringUseCase,\n );\n expect(stopDiscoveringUseCase).toBeInstanceOf(StopDiscoveringUseCase);\n\n const disconnectUseCase = container.get(discoveryTypes.DisconnectUseCase);\n expect(disconnectUseCase).toBeInstanceOf(DisconnectUseCase);\n\n const connectUseCase = container.get(discoveryTypes.ConnectUseCase);\n expect(connectUseCase).toBeInstanceOf(ConnectUseCase);\n\n const listenToAvailableDevicesUseCase = container.get(\n discoveryTypes.ListenToAvailableDevicesUseCase,\n );\n expect(listenToAvailableDevicesUseCase).toBeInstanceOf(\n ListenToAvailableDevicesUseCase,\n );\n const listConnectedDevicesUseCase = container.get(\n discoveryTypes.ListConnectedDevicesUseCase,\n );\n expect(listConnectedDevicesUseCase).toBeInstanceOf(\n ListConnectedDevicesUseCase,\n );\n const reconnectUseCase = container.get(discoveryTypes.ReconnectUseCase);\n expect(reconnectUseCase).toBeInstanceOf(ReconnectUseCase);\n });\n});\n"],
5
+ "mappings": "AAAA,OAAS,aAAAA,MAAiB,YAE1B,OAAS,iBAAAC,MAAqB,+CAE9B,OAAS,4BAAAC,MAAgC,8CACzC,OAAS,8BAAAC,MAAkC,kDAC3C,OAAS,kBAAAC,MAAsB,8CAC/B,OAAS,qBAAAC,MAAyB,iDAClC,OAAS,+BAAAC,MAAmC,2DAC5C,OAAS,mCAAAC,MAAuC,+DAChD,OAAS,oBAAAC,MAAwB,gDACjC,OAAS,2BAAAC,MAA+B,uDACxC,OAAS,0BAAAC,MAA8B,sDACvC,OAAS,uBAAAC,MAA2B,6CACpC,OAAS,2BAAAC,MAA+B,4CACxC,OAAS,8BAAAC,MAAkC,kDAC3C,OAAS,0BAAAC,MAA8B,yCAEvC,OAAS,0BAAAC,MAA8B,oBACvC,OAAS,kBAAAC,MAAsB,mBAE/B,SAAS,yBAA0B,IAAM,CACvC,IAAIC,EACAC,EACAC,EACJ,WAAW,IAAM,CACfD,EAAMH,EAAuB,CAAE,KAAM,EAAM,CAAC,EAC5CE,EAAY,IAAIjB,EAChBmB,EAAY,IAAIlB,EAEhBgB,EAAU,SACRC,EAEAP,EAAoB,EACpBT,EAAyB,CAAE,KAAM,EAAM,CAAC,EACxCC,EAA2B,EAC3BW,EAAuB,CACrB,WAAY,CAAC,GAAG,GAAG,EAAE,mBAAmB,IAAMK,CAAS,CAAC,CAC1D,CAAC,EACDP,EAAwB,CACtB,OAAQ,CACN,cAAe,kBACf,QAAS,sBACX,CACF,CAAC,EACDC,EAA2B,CACzB,OAAQ,CACN,aAAc,2BAChB,CACF,CAAC,CACH,CACF,CAAC,EACD,GAAG,kCAAmC,IAAM,CAC1C,OAAOK,CAAG,EAAE,YAAY,CAC1B,CAAC,EAED,GAAG,sCAAuC,IAAM,CAC9C,MAAME,EAA0BH,EAAU,IACxCD,EAAe,uBACjB,EACA,OAAOI,CAAuB,EAAE,eAAeX,CAAuB,EAEtE,MAAMY,EAAyBJ,EAAU,IACvCD,EAAe,sBACjB,EACA,OAAOK,CAAsB,EAAE,eAAeX,CAAsB,EAEpE,MAAMY,EAAoBL,EAAU,IAAID,EAAe,iBAAiB,EACxE,OAAOM,CAAiB,EAAE,eAAejB,CAAiB,EAE1D,MAAMkB,EAAiBN,EAAU,IAAID,EAAe,cAAc,EAClE,OAAOO,CAAc,EAAE,eAAenB,CAAc,EAEpD,MAAMoB,EAAkCP,EAAU,IAChDD,EAAe,+BACjB,EACA,OAAOQ,CAA+B,EAAE,eACtCjB,CACF,EACA,MAAMkB,EAA8BR,EAAU,IAC5CD,EAAe,2BACjB,EACA,OAAOS,CAA2B,EAAE,eAClCnB,CACF,EACA,MAAMoB,EAAmBT,EAAU,IAAID,EAAe,gBAAgB,EACtE,OAAOU,CAAgB,EAAE,eAAelB,CAAgB,CAC1D,CAAC,CACH,CAAC",
6
+ "names": ["Container", "TransportMock", "deviceModelModuleFactory", "deviceSessionModuleFactory", "ConnectUseCase", "DisconnectUseCase", "ListConnectedDevicesUseCase", "ListenToAvailableDevicesUseCase", "ReconnectUseCase", "StartDiscoveringUseCase", "StopDiscoveringUseCase", "loggerModuleFactory", "managerApiModuleFactory", "secureChannelModuleFactory", "transportModuleFactory", "discoveryModuleFactory", "discoveryTypes", "container", "mod", "transport", "startDiscoveringUseCase", "stopDiscoveringUseCase", "disconnectUseCase", "connectUseCase", "listenToAvailableDevicesUseCase", "listConnectedDevicesUseCase", "reconnectUseCase"]
7
7
  }
@@ -1,2 +1,2 @@
1
- const e={StartDiscoveringUseCase:Symbol.for("StartDiscoveringUseCase"),StopDiscoveringUseCase:Symbol.for("StopDiscoveringUseCase"),ConnectUseCase:Symbol.for("ConnectUseCase"),DisconnectUseCase:Symbol.for("DisconnectUseCase"),GetConnectedDeviceUseCase:Symbol.for("GetConnectedDeviceUseCase"),ListenToAvailableDevicesUseCase:Symbol.for("ListenToAvailableDevicesUseCase"),ListenToConnectedDeviceUseCase:Symbol.for("ListenToConnectedDeviceUseCase"),ListConnectedDevicesUseCase:Symbol.for("ListConnectedDevicesUseCase")};export{e as discoveryTypes};
1
+ const e={StartDiscoveringUseCase:Symbol.for("StartDiscoveringUseCase"),StopDiscoveringUseCase:Symbol.for("StopDiscoveringUseCase"),ConnectUseCase:Symbol.for("ConnectUseCase"),DisconnectUseCase:Symbol.for("DisconnectUseCase"),GetConnectedDeviceUseCase:Symbol.for("GetConnectedDeviceUseCase"),ListenToAvailableDevicesUseCase:Symbol.for("ListenToAvailableDevicesUseCase"),ListenToConnectedDeviceUseCase:Symbol.for("ListenToConnectedDeviceUseCase"),ListConnectedDevicesUseCase:Symbol.for("ListConnectedDevicesUseCase"),ReconnectUseCase:Symbol.for("ReconnectUseCase")};export{e as discoveryTypes};
2
2
  //# sourceMappingURL=discoveryTypes.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/discovery/di/discoveryTypes.ts"],
4
- "sourcesContent": ["export const discoveryTypes = {\n StartDiscoveringUseCase: Symbol.for(\"StartDiscoveringUseCase\"),\n StopDiscoveringUseCase: Symbol.for(\"StopDiscoveringUseCase\"),\n ConnectUseCase: Symbol.for(\"ConnectUseCase\"),\n DisconnectUseCase: Symbol.for(\"DisconnectUseCase\"),\n GetConnectedDeviceUseCase: Symbol.for(\"GetConnectedDeviceUseCase\"),\n ListenToAvailableDevicesUseCase: Symbol.for(\n \"ListenToAvailableDevicesUseCase\",\n ),\n ListenToConnectedDeviceUseCase: Symbol.for(\"ListenToConnectedDeviceUseCase\"),\n ListConnectedDevicesUseCase: Symbol.for(\"ListConnectedDevicesUseCase\"),\n};\n"],
5
- "mappings": "AAAO,MAAMA,EAAiB,CAC5B,wBAAyB,OAAO,IAAI,yBAAyB,EAC7D,uBAAwB,OAAO,IAAI,wBAAwB,EAC3D,eAAgB,OAAO,IAAI,gBAAgB,EAC3C,kBAAmB,OAAO,IAAI,mBAAmB,EACjD,0BAA2B,OAAO,IAAI,2BAA2B,EACjE,gCAAiC,OAAO,IACtC,iCACF,EACA,+BAAgC,OAAO,IAAI,gCAAgC,EAC3E,4BAA6B,OAAO,IAAI,6BAA6B,CACvE",
4
+ "sourcesContent": ["export const discoveryTypes = {\n StartDiscoveringUseCase: Symbol.for(\"StartDiscoveringUseCase\"),\n StopDiscoveringUseCase: Symbol.for(\"StopDiscoveringUseCase\"),\n ConnectUseCase: Symbol.for(\"ConnectUseCase\"),\n DisconnectUseCase: Symbol.for(\"DisconnectUseCase\"),\n GetConnectedDeviceUseCase: Symbol.for(\"GetConnectedDeviceUseCase\"),\n ListenToAvailableDevicesUseCase: Symbol.for(\n \"ListenToAvailableDevicesUseCase\",\n ),\n ListenToConnectedDeviceUseCase: Symbol.for(\"ListenToConnectedDeviceUseCase\"),\n ListConnectedDevicesUseCase: Symbol.for(\"ListConnectedDevicesUseCase\"),\n ReconnectUseCase: Symbol.for(\"ReconnectUseCase\"),\n};\n"],
5
+ "mappings": "AAAO,MAAMA,EAAiB,CAC5B,wBAAyB,OAAO,IAAI,yBAAyB,EAC7D,uBAAwB,OAAO,IAAI,wBAAwB,EAC3D,eAAgB,OAAO,IAAI,gBAAgB,EAC3C,kBAAmB,OAAO,IAAI,mBAAmB,EACjD,0BAA2B,OAAO,IAAI,2BAA2B,EACjE,gCAAiC,OAAO,IACtC,iCACF,EACA,+BAAgC,OAAO,IAAI,gCAAgC,EAC3E,4BAA6B,OAAO,IAAI,6BAA6B,EACrE,iBAAkB,OAAO,IAAI,kBAAkB,CACjD",
6
6
  "names": ["discoveryTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var S=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var p=(t,r,o,i)=>{for(var e=i>1?void 0:i?m(r,o):r,s=t.length-1,v;s>=0;s--)(v=t[s])&&(e=(i?v(r,o,e):v(e))||e);return i&&e&&S(r,o,e),e},n=(t,r)=>(o,i)=>r(o,i,t);import{inject as c,injectable as g}from"inversify";import{EitherAsync as h}from"purify-ts";import{TransportNotSupportedError as l}from"../../../api/transport/model/Errors";import{deviceSessionTypes as d}from"../../device-session/di/deviceSessionTypes";import{DeviceSession as D}from"../../device-session/model/DeviceSession";import{loggerTypes as f}from"../../logger-publisher/di/loggerTypes";import{managerApiTypes as y}from"../../manager-api/di/managerApiTypes";import{secureChannelTypes as u}from"../../secure-channel/di/secureChannelTypes";import{transportDiTypes as _}from"../../transport/di/transportDiTypes";let a=class{_transportService;_sessionService;_loggerFactory;_managerApi;_secureChannel;_logger;constructor(r,o,i,e,s){this._sessionService=o,this._transportService=r,this._loggerFactory=i,this._logger=i("ConnectUseCase"),this._managerApi=e,this._secureChannel=s}handleDeviceDisconnect(r){this._sessionService.getDeviceSessionByDeviceId(r).map(i=>{this._sessionService.removeDeviceSession(i.id)})}async execute({device:r,sessionRefresherOptions:o}){const i=this._transportService.getTransport(r.transport);return h.liftEither(i.toEither(new l(new Error("Unknown transport")))).chain(async e=>e.connect({deviceId:r.id,onDisconnect:s=>this.handleDeviceDisconnect(s)})).ifLeft(e=>{this._logger.error("Error connecting to device",{data:{deviceId:r.id,error:e}})}).map(async e=>{const s=new D({connectedDevice:e},this._loggerFactory,this._managerApi,this._secureChannel,o);return this._sessionService.addDeviceSession(s),await s.initialiseSession(),s.id}).caseOf({Left:e=>{throw e},Right:e=>e})}};a=p([g(),n(0,c(_.TransportService)),n(1,c(d.DeviceSessionService)),n(2,c(f.LoggerPublisherServiceFactory)),n(3,c(y.ManagerApiService)),n(4,c(u.SecureChannelService))],a);export{a as ConnectUseCase};
1
+ var S=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var p=(c,e,o,i)=>{for(var s=i>1?void 0:i?m(e,o):e,r=c.length-1,n;r>=0;r--)(n=c[r])&&(s=(i?n(e,o,s):n(s))||s);return i&&s&&S(e,o,s),s},t=(c,e)=>(o,i)=>e(o,i,c);import{inject as a,injectable as g}from"inversify";import{EitherAsync as h}from"purify-ts";import{TransportNotSupportedError as d}from"../../../api/transport/model/Errors";import{deviceSessionTypes as l}from"../../device-session/di/deviceSessionTypes";import{DeviceSession as D}from"../../device-session/model/DeviceSession";import{loggerTypes as f}from"../../logger-publisher/di/loggerTypes";import{managerApiTypes as y}from"../../manager-api/di/managerApiTypes";import{secureChannelTypes as u}from"../../secure-channel/di/secureChannelTypes";import{transportDiTypes as _}from"../../transport/di/transportDiTypes";let v=class{_transportService;_sessionService;_loggerFactory;_managerApi;_secureChannel;_logger;constructor(e,o,i,s,r){this._sessionService=o,this._transportService=e,this._loggerFactory=i,this._logger=i("ConnectUseCase"),this._managerApi=s,this._secureChannel=r}handleDeviceDisconnect(e){this._sessionService.getDeviceSessionByDeviceId(e).map(i=>{this._sessionService.removeDeviceSession(i.id)})}async execute({device:e,sessionRefresherOptions:o}){const i=this._transportService.getTransport(e.transport),s="sessionId"in e?e.sessionId:void 0;return h.liftEither(i.toEither(new d(new Error("Unknown transport")))).chain(async r=>r.connect({deviceId:e.id,onDisconnect:n=>this.handleDeviceDisconnect(n)})).ifLeft(r=>{this._logger.error("Error connecting to device",{data:{deviceId:e.id,error:r}})}).map(async r=>{const n=new D({connectedDevice:r,id:s},this._loggerFactory,this._managerApi,this._secureChannel,o);return this._sessionService.addDeviceSession(n),await n.initialiseSession(),n.id}).caseOf({Left:r=>{throw r},Right:r=>r})}};v=p([g(),t(0,a(_.TransportService)),t(1,a(l.DeviceSessionService)),t(2,a(f.LoggerPublisherServiceFactory)),t(3,a(y.ManagerApiService)),t(4,a(u.SecureChannelService))],v);export{v as ConnectUseCase};
2
2
  //# sourceMappingURL=ConnectUseCase.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/discovery/use-case/ConnectUseCase.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { EitherAsync } from \"purify-ts\";\n\nimport { DeviceSessionId } from \"@api/device-session/types\";\nimport { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { DiscoveredDevice } from \"@api/transport/model/DiscoveredDevice\";\nimport { TransportNotSupportedError } from \"@api/transport/model/Errors\";\nimport { DeviceId } from \"@api/types\";\nimport { deviceSessionTypes } from \"@internal/device-session/di/deviceSessionTypes\";\nimport {\n DeviceSession,\n DeviceSessionRefresherOptions,\n} from \"@internal/device-session/model/DeviceSession\";\nimport type { DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport type { ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { secureChannelTypes } from \"@internal/secure-channel/di/secureChannelTypes\";\nimport type { SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\nimport { transportDiTypes } from \"@internal/transport/di/transportDiTypes\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\n/**\n * The arguments for the ConnectUseCase.\n */\nexport type ConnectUseCaseArgs = {\n /**\n * UUID of the device got from device discovery `StartDiscoveringUseCase`\n */\n device: DiscoveredDevice;\n\n /**\n * sessionRefresherOptions - optional\n * isRefresherDisabled - whether the refresher is disabled\n * pollingInterval - optional - the refresh interval in milliseconds\n */\n sessionRefresherOptions?: DeviceSessionRefresherOptions;\n};\n\n/**\n * Connects to a discovered device.\n */\n@injectable()\nexport class ConnectUseCase {\n private readonly _transportService: TransportService;\n private readonly _sessionService: DeviceSessionService;\n private readonly _loggerFactory: (tag: string) => LoggerPublisherService;\n private readonly _managerApi: ManagerApiService;\n private readonly _secureChannel: SecureChannelService;\n private readonly _logger: LoggerPublisherService;\n\n constructor(\n @inject(transportDiTypes.TransportService)\n transportService: TransportService,\n @inject(deviceSessionTypes.DeviceSessionService)\n sessionService: DeviceSessionService,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n @inject(managerApiTypes.ManagerApiService)\n managerApi: ManagerApiService,\n @inject(secureChannelTypes.SecureChannelService)\n secureChannel: SecureChannelService,\n ) {\n this._sessionService = sessionService;\n this._transportService = transportService;\n this._loggerFactory = loggerFactory;\n this._logger = loggerFactory(\"ConnectUseCase\");\n this._managerApi = managerApi;\n this._secureChannel = secureChannel;\n }\n\n private handleDeviceDisconnect(deviceId: DeviceId) {\n const deviceSessionOrError =\n this._sessionService.getDeviceSessionByDeviceId(deviceId);\n deviceSessionOrError.map((deviceSession) => {\n this._sessionService.removeDeviceSession(deviceSession.id);\n });\n }\n\n async execute({\n device,\n sessionRefresherOptions,\n }: ConnectUseCaseArgs): Promise<DeviceSessionId> {\n const transport = this._transportService.getTransport(device.transport);\n\n return EitherAsync.liftEither(\n transport.toEither(\n new TransportNotSupportedError(new Error(\"Unknown transport\")),\n ),\n )\n .chain(async (t) => {\n return t.connect({\n deviceId: device.id,\n onDisconnect: (dId) => this.handleDeviceDisconnect(dId),\n });\n })\n .ifLeft((error) => {\n this._logger.error(\"Error connecting to device\", {\n data: { deviceId: device.id, error },\n });\n })\n .map(async (connectedDevice) => {\n const deviceSession = new DeviceSession(\n { connectedDevice },\n this._loggerFactory,\n this._managerApi,\n this._secureChannel,\n sessionRefresherOptions,\n );\n this._sessionService.addDeviceSession(deviceSession);\n await deviceSession.initialiseSession();\n return deviceSession.id;\n })\n .caseOf({\n Left: (error) => {\n throw error;\n },\n Right: (s) => s,\n });\n }\n}\n"],
5
- "mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YACnC,OAAS,eAAAC,MAAmB,YAK5B,OAAS,8BAAAC,MAAkC,8BAE3C,OAAS,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KAAOQ,GAAU,CACf,MAAMA,CACR,EACA,MAAQG,GAAMA,CAChB,CAAC,CACL,CACF,EA7EalB,EAANmB,EAAA,CADNC,EAAW,EAUPC,EAAA,EAAAC,EAAOC,EAAiB,gBAAgB,GAExCF,EAAA,EAAAC,EAAOE,EAAmB,oBAAoB,GAE9CH,EAAA,EAAAC,EAAOG,EAAY,6BAA6B,GAEhDJ,EAAA,EAAAC,EAAOI,EAAgB,iBAAiB,GAExCL,EAAA,EAAAC,EAAOK,EAAmB,oBAAoB,IAjBtC3B",
6
- "names": ["inject", "injectable", "EitherAsync", "TransportNotSupportedError", "deviceSessionTypes", "DeviceSession", "loggerTypes", "managerApiTypes", "secureChannelTypes", "transportDiTypes", "ConnectUseCase", "transportService", "sessionService", "loggerFactory", "managerApi", "secureChannel", "deviceId", "deviceSession", "device", "sessionRefresherOptions", "transport", "EitherAsync", "TransportNotSupportedError", "t", "dId", "error", "connectedDevice", "DeviceSession", "s", "__decorateClass", "injectable", "__decorateParam", "inject", "transportDiTypes", "deviceSessionTypes", "loggerTypes", "managerApiTypes", "secureChannelTypes"]
4
+ "sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { EitherAsync } from \"purify-ts\";\n\nimport { DeviceSessionId } from \"@api/device-session/types\";\nimport { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { ConnectedDevice } from \"@api/transport/model/ConnectedDevice\";\nimport { DiscoveredDevice } from \"@api/transport/model/DiscoveredDevice\";\nimport { TransportNotSupportedError } from \"@api/transport/model/Errors\";\nimport { DeviceId } from \"@api/types\";\nimport { deviceSessionTypes } from \"@internal/device-session/di/deviceSessionTypes\";\nimport {\n DeviceSession,\n DeviceSessionRefresherOptions,\n} from \"@internal/device-session/model/DeviceSession\";\nimport type { DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport type { ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { secureChannelTypes } from \"@internal/secure-channel/di/secureChannelTypes\";\nimport type { SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\nimport { transportDiTypes } from \"@internal/transport/di/transportDiTypes\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\n/**\n * The arguments for the ConnectUseCase.\n */\nexport type ConnectUseCaseArgs = {\n /**\n * Discovered device or connected device.\n */\n device: DiscoveredDevice | ConnectedDevice;\n\n /**\n * sessionRefresherOptions - optional\n * isRefresherDisabled - whether the refresher is disabled\n * pollingInterval - optional - the refresh interval in milliseconds\n */\n sessionRefresherOptions?: DeviceSessionRefresherOptions;\n};\n\n/**\n * Connects to a discovered device.\n */\n@injectable()\nexport class ConnectUseCase {\n private readonly _transportService: TransportService;\n private readonly _sessionService: DeviceSessionService;\n private readonly _loggerFactory: (tag: string) => LoggerPublisherService;\n private readonly _managerApi: ManagerApiService;\n private readonly _secureChannel: SecureChannelService;\n private readonly _logger: LoggerPublisherService;\n\n constructor(\n @inject(transportDiTypes.TransportService)\n transportService: TransportService,\n @inject(deviceSessionTypes.DeviceSessionService)\n sessionService: DeviceSessionService,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n @inject(managerApiTypes.ManagerApiService)\n managerApi: ManagerApiService,\n @inject(secureChannelTypes.SecureChannelService)\n secureChannel: SecureChannelService,\n ) {\n this._sessionService = sessionService;\n this._transportService = transportService;\n this._loggerFactory = loggerFactory;\n this._logger = loggerFactory(\"ConnectUseCase\");\n this._managerApi = managerApi;\n this._secureChannel = secureChannel;\n }\n\n private handleDeviceDisconnect(deviceId: DeviceId) {\n const deviceSessionOrError =\n this._sessionService.getDeviceSessionByDeviceId(deviceId);\n deviceSessionOrError.map((deviceSession) => {\n this._sessionService.removeDeviceSession(deviceSession.id);\n });\n }\n\n async execute({\n device,\n sessionRefresherOptions,\n }: ConnectUseCaseArgs): Promise<DeviceSessionId> {\n const transport = this._transportService.getTransport(device.transport);\n // In case of a connected device, we reconnect using the same session id.\n // If not provided, a new device session id will be generated.\n const deviceSessionId =\n \"sessionId\" in device ? device.sessionId : undefined;\n\n return EitherAsync.liftEither(\n transport.toEither(\n new TransportNotSupportedError(new Error(\"Unknown transport\")),\n ),\n )\n .chain(async (t) => {\n return t.connect({\n deviceId: device.id,\n onDisconnect: (dId) => this.handleDeviceDisconnect(dId),\n });\n })\n .ifLeft((error) => {\n this._logger.error(\"Error connecting to device\", {\n data: { deviceId: device.id, error },\n });\n })\n .map(async (connectedDevice) => {\n const deviceSession = new DeviceSession(\n { connectedDevice, id: deviceSessionId },\n this._loggerFactory,\n this._managerApi,\n this._secureChannel,\n sessionRefresherOptions,\n );\n this._sessionService.addDeviceSession(deviceSession);\n await deviceSession.initialiseSession();\n return deviceSession.id;\n })\n .caseOf({\n Left: (error) => {\n throw error;\n },\n Right: (s) => s,\n });\n }\n}\n"],
5
+ "mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YACnC,OAAS,eAAAC,MAAmB,YAM5B,OAAS,8BAAAC,MAAkC,8BAE3C,OAAS,sBAAAC,MAA0B,iDACnC,OACE,iBAAAC,MAEK,+CAEP,OAAS,eAAAC,MAAmB,4CAC5B,OAAS,mBAAAC,MAAuB,2CAEhC,OAAS,sBAAAC,MAA0B,iDAEnC,OAAS,oBAAAC,MAAwB,0CAwB1B,IAAMC,EAAN,KAAqB,CACT,kBACA,gBACA,eACA,YACA,eACA,QAEjB,YAEEC,EAEAC,EAEAC,EAEAC,EAEAC,EACA,CACA,KAAK,gBAAkBH,EACvB,KAAK,kBAAoBD,EACzB,KAAK,eAAiBE,EACtB,KAAK,QAAUA,EAAc,gBAAgB,EAC7C,KAAK,YAAcC,EACnB,KAAK,eAAiBC,CACxB,CAEQ,uBAAuBC,EAAoB,CAE/C,KAAK,gBAAgB,2BAA2BA,CAAQ,EACrC,IAAKC,GAAkB,CAC1C,KAAK,gBAAgB,oBAAoBA,EAAc,EAAE,CAC3D,CAAC,CACH,CAEA,MAAM,QAAQ,CACZ,OAAAC,EACA,wBAAAC,CACF,EAAiD,CAC/C,MAAMC,EAAY,KAAK,kBAAkB,aAAaF,EAAO,SAAS,EAGhEG,EACJ,cAAeH,EAASA,EAAO,UAAY,OAE7C,OAAOI,EAAY,WACjBF,EAAU,SACR,IAAIG,EAA2B,IAAI,MAAM,mBAAmB,CAAC,CAC/D,CACF,EACG,MAAM,MAAOC,GACLA,EAAE,QAAQ,CACf,SAAUN,EAAO,GACjB,aAAeO,GAAQ,KAAK,uBAAuBA,CAAG,CACxD,CAAC,CACF,EACA,OAAQC,GAAU,CACjB,KAAK,QAAQ,MAAM,6BAA8B,CAC/C,KAAM,CAAE,SAAUR,EAAO,GAAI,MAAAQ,CAAM,CACrC,CAAC,CACH,CAAC,EACA,IAAI,MAAOC,GAAoB,CAC9B,MAAMV,EAAgB,IAAIW,EACxB,CAAE,gBAAAD,EAAiB,GAAIN,CAAgB,EACvC,KAAK,eACL,KAAK,YACL,KAAK,eACLF,CACF,EACA,YAAK,gBAAgB,iBAAiBF,CAAa,EACnD,MAAMA,EAAc,kBAAkB,EAC/BA,EAAc,EACvB,CAAC,EACA,OAAO,CACN,KAAOS,GAAU,CACf,MAAMA,CACR,EACA,MAAQG,GAAMA,CAChB,CAAC,CACL,CACF,EAjFanB,EAANoB,EAAA,CADNC,EAAW,EAUPC,EAAA,EAAAC,EAAOC,EAAiB,gBAAgB,GAExCF,EAAA,EAAAC,EAAOE,EAAmB,oBAAoB,GAE9CH,EAAA,EAAAC,EAAOG,EAAY,6BAA6B,GAEhDJ,EAAA,EAAAC,EAAOI,EAAgB,iBAAiB,GAExCL,EAAA,EAAAC,EAAOK,EAAmB,oBAAoB,IAjBtC5B",
6
+ "names": ["inject", "injectable", "EitherAsync", "TransportNotSupportedError", "deviceSessionTypes", "DeviceSession", "loggerTypes", "managerApiTypes", "secureChannelTypes", "transportDiTypes", "ConnectUseCase", "transportService", "sessionService", "loggerFactory", "managerApi", "secureChannel", "deviceId", "deviceSession", "device", "sessionRefresherOptions", "transport", "deviceSessionId", "EitherAsync", "TransportNotSupportedError", "t", "dId", "error", "connectedDevice", "DeviceSession", "s", "__decorateClass", "injectable", "__decorateParam", "inject", "transportDiTypes", "deviceSessionTypes", "loggerTypes", "managerApiTypes", "secureChannelTypes"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as g,Maybe as p,Right as d}from"purify-ts";import{TransportMock as y}from"../../../api/transport/model/__mocks__/TransportMock";import{UnknownDeviceError as m}from"../../../api/transport/model/Errors";import{connectedDeviceStubBuilder as k}from"../../../api/transport/model/TransportConnectedDevice.stub";import{DefaultDeviceSessionService as C}from"../../device-session/service/DefaultDeviceSessionService";import{DefaultLoggerPublisherService as w}from"../../logger-publisher/service/DefaultLoggerPublisherService";import{AxiosManagerApiDataSource as A}from"../../manager-api/data/AxiosManagerApiDataSource";import{DefaultManagerApiService as h}from"../../manager-api/service/DefaultManagerApiService";import{DefaultSecureChannelDataSource as M}from"../../secure-channel/data/DefaultSecureChannelDataSource";import{DefaultSecureChannelService as T}from"../../secure-channel/service/DefaultSecureChannelService";import{DefaultTransportService as b}from"../../transport/service/DefaultTransportService";import{ConnectUseCase as v}from"./ConnectUseCase";vi.mock("uuid",()=>({v4:vi.fn().mockReturnValue("fakeSessionId")}));vi.mock("@internal/manager-api/data/AxiosManagerApiDataSource");vi.mock("@internal/transport/service/DefaultTransportService");let r,o,i,e,n,S,u,a;const I="fakeSessionId";describe("ConnectUseCase",()=>{const c={id:"",deviceModel:{},transport:"USB",name:"TEST"},f=k({id:"1"}),l="logger-tag";beforeAll(()=>{i=new w([],l),r=new y,e=new C(()=>i),S=new A({}),n=new h(S),u=new M({}),a=new T(u),o=new b}),afterEach(()=>{for(const t of e.getDeviceSessions())e.removeDeviceSession(t.id)}),afterAll(()=>{vi.restoreAllMocks()}),test("If connect use case encounter an error, return it",async()=>{vi.spyOn(r,"connect").mockResolvedValue(g(new m)),vi.spyOn(o,"getTransport").mockReturnValue(p.of(r));const t=new v(o,e,()=>i,n,a);await expect(t.execute({device:c})).rejects.toBeInstanceOf(m)}),test("If connect is in success, return a deviceSession id",async()=>{vi.spyOn(r,"connect").mockResolvedValue(d(f)),vi.spyOn(o,"getTransport").mockReturnValue(p.of(r)),vi.spyOn(e,"addDeviceSession").mockImplementation(D=>(D.setDeviceSessionState({}),e));const s=await new v(o,e,()=>i,n,a).execute({device:c});expect(s).toBe(I),e.removeDeviceSession(s)})});
1
+ import{Left as k,Maybe as m,Right as S}from"purify-ts";import{TransportMock as C}from"../../../api/transport/model/__mocks__/TransportMock";import{UnknownDeviceError as f}from"../../../api/transport/model/Errors";import{connectedDeviceStubBuilder as w}from"../../../api/transport/model/TransportConnectedDevice.stub";import{DefaultDeviceSessionService as I}from"../../device-session/service/DefaultDeviceSessionService";import{DefaultLoggerPublisherService as M}from"../../logger-publisher/service/DefaultLoggerPublisherService";import{AxiosManagerApiDataSource as T}from"../../manager-api/data/AxiosManagerApiDataSource";import{DefaultManagerApiService as h}from"../../manager-api/service/DefaultManagerApiService";import{DefaultSecureChannelDataSource as A}from"../../secure-channel/data/DefaultSecureChannelDataSource";import{DefaultSecureChannelService as b}from"../../secure-channel/service/DefaultSecureChannelService";import{DefaultTransportService as O}from"../../transport/service/DefaultTransportService";import{ConnectUseCase as p}from"./ConnectUseCase";vi.mock("uuid",()=>({v4:vi.fn().mockReturnValue("fakeSessionId")}));vi.mock("@internal/manager-api/data/AxiosManagerApiDataSource");vi.mock("@internal/transport/service/DefaultTransportService");let o,n,i,e,s,l,d,c;const x="fakeSessionId",D="fakeSessionIdConnectedDevice";describe("ConnectUseCase",()=>{const v={id:"",deviceModel:{},transport:"USB",name:"TEST"},u=w({id:"1"}),g={id:"1",sessionId:D,modelId:"model-id",name:"device-name",type:"MOCK",transport:"USB"},y="logger-tag";beforeAll(()=>{i=new M([],y),o=new C,e=new I(()=>i),l=new T({}),s=new h(l),d=new A({}),c=new b(d),n=new O}),afterEach(()=>{for(const t of e.getDeviceSessions())e.removeDeviceSession(t.id)}),afterAll(()=>{vi.restoreAllMocks()}),test("If connect use case encounter an error, return it",async()=>{vi.spyOn(o,"connect").mockResolvedValue(k(new f)),vi.spyOn(n,"getTransport").mockReturnValue(m.of(o));const t=new p(n,e,()=>i,s,c);await expect(t.execute({device:v})).rejects.toBeInstanceOf(f)}),test("If connect is in success, return a deviceSession id",async()=>{vi.spyOn(o,"connect").mockResolvedValue(S(u)),vi.spyOn(n,"getTransport").mockReturnValue(m.of(o)),vi.spyOn(e,"addDeviceSession").mockImplementation(a=>(a.setDeviceSessionState({}),e));const r=await new p(n,e,()=>i,s,c).execute({device:v});expect(r).toBe(x),e.removeDeviceSession(r)}),test("If connect is in success after a reconnect, return the same deviceSession id",async()=>{vi.spyOn(o,"connect").mockResolvedValue(S(u)),vi.spyOn(n,"getTransport").mockReturnValue(m.of(o)),vi.spyOn(e,"addDeviceSession").mockImplementation(a=>(a.setDeviceSessionState({}),e));const r=await new p(n,e,()=>i,s,c).execute({device:g});expect(r).toBe(D),e.removeDeviceSession(r)})});
2
2
  //# sourceMappingURL=ConnectUseCase.test.js.map