@ledgerhq/device-management-kit 0.0.0-rnble-transport-20250307123452 → 0.0.0-rnble-transport-20250312161847

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 (117) hide show
  1. package/lib/cjs/package.json +2 -2
  2. package/lib/cjs/src/api/device-action/model/UserInteractionRequired.js.map +1 -1
  3. package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js +1 -1
  4. package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js.map +3 -3
  5. package/lib/cjs/src/api/index.js +1 -1
  6. package/lib/cjs/src/api/index.js.map +3 -3
  7. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
  8. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/types.js +1 -1
  9. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/types.js.map +1 -1
  10. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +2 -0
  11. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +7 -0
  12. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.test.js +2 -0
  13. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.test.js.map +7 -0
  14. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js +2 -0
  15. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +7 -0
  16. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  17. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +2 -2
  18. package/lib/cjs/src/api/secure-channel/task/types.js +1 -1
  19. package/lib/cjs/src/api/secure-channel/task/types.js.map +1 -1
  20. package/lib/cjs/src/api/secure-channel/types.js +2 -0
  21. package/lib/cjs/src/api/secure-channel/types.js.map +7 -0
  22. package/lib/cjs/src/api/types.js +1 -1
  23. package/lib/cjs/src/api/types.js.map +1 -1
  24. package/lib/cjs/src/internal/device-session/model/DeviceSession.js +1 -1
  25. package/lib/cjs/src/internal/device-session/model/DeviceSession.js.map +2 -2
  26. package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.js +1 -1
  27. package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.js.map +3 -3
  28. package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js +1 -1
  29. package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js.map +3 -3
  30. package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js +1 -1
  31. package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js.map +1 -1
  32. package/lib/cjs/src/internal/manager-api/data/ManagerApiDto.js +1 -1
  33. package/lib/cjs/src/internal/manager-api/data/ManagerApiDto.js.map +1 -1
  34. package/lib/cjs/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js +1 -1
  35. package/lib/cjs/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js.map +2 -2
  36. package/lib/cjs/src/internal/manager-api/model/Application.js +1 -1
  37. package/lib/cjs/src/internal/manager-api/model/Application.js.map +1 -1
  38. package/lib/cjs/src/internal/manager-api/model/Params.js +2 -0
  39. package/lib/cjs/src/internal/manager-api/model/Params.js.map +7 -0
  40. package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.js +1 -1
  41. package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.js.map +3 -3
  42. package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.test.js +1 -1
  43. package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.test.js.map +3 -3
  44. package/lib/cjs/src/internal/manager-api/service/ManagerApiService.js +1 -1
  45. package/lib/cjs/src/internal/manager-api/service/ManagerApiService.js.map +1 -1
  46. package/lib/esm/package.json +2 -2
  47. package/lib/esm/src/api/device-action/model/UserInteractionRequired.js.map +1 -1
  48. package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js +1 -1
  49. package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js.map +3 -3
  50. package/lib/esm/src/api/index.js +1 -1
  51. package/lib/esm/src/api/index.js.map +3 -3
  52. package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
  53. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +2 -0
  54. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +7 -0
  55. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.test.js +2 -0
  56. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.test.js.map +7 -0
  57. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/types.js +2 -0
  58. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +7 -0
  59. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  60. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +2 -2
  61. package/lib/esm/src/api/secure-channel/task/types.js.map +1 -1
  62. package/lib/esm/src/api/secure-channel/types.js +1 -0
  63. package/lib/esm/src/api/secure-channel/types.js.map +7 -0
  64. package/lib/esm/src/internal/device-session/model/DeviceSession.js +1 -1
  65. package/lib/esm/src/internal/device-session/model/DeviceSession.js.map +2 -2
  66. package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.js +1 -1
  67. package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.js.map +3 -3
  68. package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js +1 -1
  69. package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js.map +3 -3
  70. package/lib/esm/src/internal/manager-api/data/ManagerApiDto.js.map +1 -1
  71. package/lib/esm/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js +1 -1
  72. package/lib/esm/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js.map +2 -2
  73. package/lib/esm/src/internal/manager-api/model/Application.js.map +1 -1
  74. package/lib/esm/src/internal/manager-api/model/Params.js +1 -0
  75. package/lib/esm/src/internal/manager-api/model/Params.js.map +7 -0
  76. package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.js +1 -1
  77. package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.js.map +3 -3
  78. package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.test.js +1 -1
  79. package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.test.js.map +3 -3
  80. package/lib/types/src/api/device-action/model/UserInteractionRequired.d.ts +1 -1
  81. package/lib/types/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.d.ts.map +1 -1
  82. package/lib/types/src/api/index.d.ts +1 -0
  83. package/lib/types/src/api/index.d.ts.map +1 -1
  84. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.d.ts.map +1 -1
  85. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts +5 -7
  86. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts.map +1 -1
  87. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.d.ts +8 -0
  88. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.d.ts.map +1 -0
  89. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.test.d.ts +1 -0
  90. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.test.d.ts.map +1 -0
  91. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts +59 -0
  92. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts.map +1 -0
  93. package/lib/types/src/api/secure-channel/task/types.d.ts +1 -1
  94. package/lib/types/src/api/secure-channel/task/types.d.ts.map +1 -1
  95. package/lib/types/src/api/secure-channel/types.d.ts +4 -0
  96. package/lib/types/src/api/secure-channel/types.d.ts.map +1 -0
  97. package/lib/types/src/api/types.d.ts +1 -0
  98. package/lib/types/src/api/types.d.ts.map +1 -1
  99. package/lib/types/src/internal/device-session/model/DeviceSession.d.ts.map +1 -1
  100. package/lib/types/src/internal/manager-api/data/AxiosManagerApiDataSource.d.ts +6 -5
  101. package/lib/types/src/internal/manager-api/data/AxiosManagerApiDataSource.d.ts.map +1 -1
  102. package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts +14 -9
  103. package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts.map +1 -1
  104. package/lib/types/src/internal/manager-api/data/ManagerApiDto.d.ts +4 -1
  105. package/lib/types/src/internal/manager-api/data/ManagerApiDto.d.ts.map +1 -1
  106. package/lib/types/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.d.ts +1 -0
  107. package/lib/types/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.d.ts.map +1 -1
  108. package/lib/types/src/internal/manager-api/model/Application.d.ts +4 -1
  109. package/lib/types/src/internal/manager-api/model/Application.d.ts.map +1 -1
  110. package/lib/types/src/internal/manager-api/model/Params.d.ts +43 -0
  111. package/lib/types/src/internal/manager-api/model/Params.d.ts.map +1 -0
  112. package/lib/types/src/internal/manager-api/service/DefaultManagerApiService.d.ts +5 -5
  113. package/lib/types/src/internal/manager-api/service/DefaultManagerApiService.d.ts.map +1 -1
  114. package/lib/types/src/internal/manager-api/service/ManagerApiService.d.ts +33 -2
  115. package/lib/types/src/internal/manager-api/service/ManagerApiService.d.ts.map +1 -1
  116. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  117. package/package.json +2 -2
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/secure-channel/task/ConnectToSecureChannelTask.ts"],
4
- "sourcesContent": ["import WebSocket from \"isomorphic-ws\";\nimport { type Either } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { CommandUtils } from \"@api/command/utils/CommandUtils\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n InMessageQueryEnum,\n type InMessageType,\n OutMessageResponseEnum,\n type OutMessageType,\n type SecureChannelEvent,\n SecureChannelEventType,\n} from \"@api/secure-channel/task/types\";\nimport {\n isRefusedByUser,\n willRequestPermission,\n} from \"@api/secure-channel/utils\";\nimport { bufferToHexaString, hexaStringToBuffer } from \"@api/utils/HexaString\";\nimport {\n SecureChannelError,\n type WebSocketConnectionError,\n} from \"@internal/secure-channel/model/Errors\";\n\nexport type ConnectToSecureChannelTaskArgs = {\n connection: Either<WebSocketConnectionError, WebSocket>;\n};\n\nexport class ConnectToSecureChannelTask {\n private readonly _connection: WebSocket;\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: ConnectToSecureChannelTaskArgs,\n ) {\n if (this._args.connection.isRight()) {\n this._connection = this._args.connection.extract();\n } else {\n throw new SecureChannelError(\n `Invalid WebSocket connection: ${String(this._args.connection.extract())}`,\n );\n }\n }\n\n run(): Observable<SecureChannelEvent> {\n const reenableRefresher = this._api.disableRefresher(\n \"connectToSecureChannel\",\n );\n\n const obs = new Observable<SecureChannelEvent>((subscriber) => {\n let unsubscribed: boolean = false;\n let inBulkMode = false;\n let communicationFinished = false;\n let deviceError: SecureChannelError | null = null;\n let waitingForUserAction = false;\n\n this._connection.onopen = () => {\n subscriber.next({\n type: SecureChannelEventType.Opened,\n });\n };\n\n this._connection.onerror = (error) => {\n // When the bulk sending is in progress, network error is ignored\n if (inBulkMode) {\n return;\n }\n\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: error.message,\n }),\n );\n };\n\n this._connection.onclose = () => {\n // When the bulk sending is in progress, network event is ignored\n if (inBulkMode) {\n return;\n }\n\n if (communicationFinished) {\n subscriber.next({\n type: SecureChannelEventType.Closed,\n });\n subscriber.complete();\n } else {\n subscriber.error(\n new SecureChannelError(\n deviceError ?? {\n url: this._connection.url,\n errorMessage: \"Connection closed unexpectedly\",\n },\n ),\n );\n }\n };\n\n this._connection.onmessage = async (event) => {\n // When unsubscribed, ignore the message\n if (unsubscribed) {\n return;\n }\n deviceError = null;\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const input: InMessageType = JSON.parse(String(event.data));\n\n switch (input.query) {\n case InMessageQueryEnum.EXCHANGE: {\n const { nonce } = input;\n\n if (Array.isArray(input.data)) {\n subscriber.error(\n new SecureChannelError(\n `${InMessageQueryEnum.EXCHANGE} data type should not be Array`,\n ),\n );\n break;\n }\n\n const apdu = hexaStringToBuffer(input.data);\n\n if (apdu === null || apdu.length < 5) {\n subscriber.error(\n new SecureChannelError(\n `Received invalid APDU data: ${input.data}`,\n ),\n );\n break;\n }\n\n subscriber.next({\n type: SecureChannelEventType.PreExchange,\n payload: { nonce, apdu },\n });\n\n if (\n willRequestPermission(apdu) &&\n !this.isSecureConnectionAllowed()\n ) {\n waitingForUserAction = true;\n subscriber.next({\n type: SecureChannelEventType.PermissionRequested,\n });\n }\n\n const response = await this._api.sendApdu(apdu);\n\n if (unsubscribed) {\n return;\n }\n\n response.caseOf({\n Left: (error) => {\n subscriber.error(new SecureChannelError(error));\n },\n Right: (apduResponse: ApduResponse) => {\n let outMessageResponse: OutMessageResponseEnum;\n /**\n * | Status Code | Description | Event Emitted |\n * |-------------|------------------------------------|------------------------------------|\n * | 0x9000 | Success | SecureChannelEventEnum.Exchange |\n * | 0x5515 | Device is locked | Error |\n * | 0x5501 | User refused on the device | Error |\n * | 0x6985 | Condition of use not satisfied | Error |\n */\n // Success response\n if (CommandUtils.isSuccessResponse(apduResponse)) {\n outMessageResponse = OutMessageResponseEnum.SUCCESS;\n // Emit event for the exchange\n subscriber.next({\n type: SecureChannelEventType.Exchange,\n payload: {\n nonce,\n apdu,\n data: apduResponse.data,\n status: apduResponse.statusCode,\n },\n });\n } else {\n outMessageResponse = OutMessageResponseEnum.ERROR;\n\n deviceError = new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Invalid status code: ${bufferToHexaString(\n apduResponse.statusCode,\n )}`,\n });\n\n // Device is locked\n if (CommandUtils.isLockedDeviceResponse(apduResponse)) {\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Device is locked`,\n }),\n );\n return;\n }\n\n // User refused the permission\n if (\n isRefusedByUser(apduResponse.statusCode) &&\n waitingForUserAction\n ) {\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: \"User refused on the device\",\n }),\n );\n return;\n }\n }\n\n if (waitingForUserAction) {\n subscriber.next({\n type: SecureChannelEventType.PermissionGranted,\n });\n waitingForUserAction = false;\n }\n\n // Send the message back to the server\n const message: OutMessageType = {\n nonce,\n response: outMessageResponse,\n data: bufferToHexaString(apduResponse.data).slice(2),\n };\n this._connection.send(JSON.stringify(message));\n },\n });\n break;\n }\n case InMessageQueryEnum.BULK: {\n inBulkMode = true;\n this._connection.close();\n\n if (!Array.isArray(input.data) || input.data.length === 0) {\n subscriber.error(\n new SecureChannelError(\"Invalid bulk data received\"),\n );\n break;\n }\n\n const apdus = input.data.reduce(\n (acc: Array<Uint8Array>, cur: string) => {\n const apdu = hexaStringToBuffer(cur);\n return apdu === null ? acc : [...acc, apdu];\n },\n [],\n );\n\n for (let i = 0, len = apdus.length; i < len; i++) {\n await this._api.sendApdu(apdus[i]!);\n if (unsubscribed) {\n subscriber.error(\n new SecureChannelError(\n \"Bulk sending cancelled by unsubscribing\",\n ),\n );\n break;\n }\n subscriber.next({\n type: SecureChannelEventType.Progress,\n payload: {\n progress: +Number((i + 1) / len).toFixed(2),\n index: i,\n total: len,\n },\n });\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.SUCCESS: {\n // Ignore success message when in bulk mode\n if (inBulkMode) {\n break;\n }\n // Emit the result if there is any\n const payload = input.result ?? input.data;\n if (payload) {\n subscriber.next({\n type: SecureChannelEventType.Result,\n payload: String(payload ?? \"\"),\n });\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.WARNING: {\n // Ignore warning message when in bulk mode\n if (inBulkMode) {\n break;\n }\n subscriber.next({\n type: SecureChannelEventType.Warning,\n payload: { message: String(input.data) },\n });\n break;\n }\n case InMessageQueryEnum.ERROR: {\n if (inBulkMode) {\n break;\n }\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: String(input.data),\n }),\n );\n }\n }\n } catch (error) {\n deviceError = new SecureChannelError(error);\n subscriber.error(deviceError);\n }\n };\n\n return () => {\n reenableRefresher();\n unsubscribed = true;\n // Close the connection if it is open when unsubscribing\n if (this._connection.readyState === WebSocket.OPEN) {\n this._connection.close();\n }\n };\n });\n\n return obs;\n }\n\n /**\n * Determines if a secure connection is already allowed based on the current device session state.\n *\n * @returns {boolean} `true` if a secure connection is allowed, otherwise `false`.\n */\n isSecureConnectionAllowed(): boolean {\n const deviceSessionState = this._api.getDeviceSessionState();\n return (\n \"isSecureConnectionAllowed\" in deviceSessionState &&\n deviceSessionState.isSecureConnectionAllowed\n );\n }\n}\n"],
5
- "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAsB,4BAEtBC,EAA2B,gBAE3BC,EAA6B,2CAG7BC,EAOO,0CACPC,EAGO,qCACPC,EAAuD,iCACvDC,EAGO,iDAMA,MAAMR,CAA2B,CAEtC,YACmBS,EACAC,EACjB,CAFiB,UAAAD,EACA,WAAAC,EAEjB,GAAI,KAAK,MAAM,WAAW,QAAQ,EAChC,KAAK,YAAc,KAAK,MAAM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AIN,EACF,MAEFF,EAAW,MACT,IAAI,qBAAmB,CACrB,IAAK,KAAK,YAAY,IACtB,aAAc,OAAOQ,EAAM,IAAI,CACjC,CAAC,CACH,CACF,CACF,CACF,OAASF,EAAO,CACdF,EAAc,IAAI,qBAAmBE,CAAK,EAC1CN,EAAW,MAAMI,CAAW,CAC9B,EACF,EAEO,IAAM,CACXL,EAAkB,EAClBE,EAAe,GAEX,KAAK,YAAY,aAAe,EAAAoB,QAAU,MAC5C,KAAK,YAAY,MAAM,CAE3B,CACF,CAAC,CAGH,CAOA,2BAAqC,CACnC,MAAMC,EAAqB,KAAK,KAAK,sBAAsB,EAC3D,MACE,8BAA+BA,GAC/BA,EAAmB,yBAEvB,CACF",
4
+ "sourcesContent": ["import WebSocket from \"isomorphic-ws\";\nimport { type Either } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { CommandUtils } from \"@api/command/utils/CommandUtils\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n InMessageQueryEnum,\n type InMessageType,\n OutMessageResponseEnum,\n type OutMessageType,\n type SecureChannelEvent,\n SecureChannelEventType,\n} from \"@api/secure-channel/task/types\";\nimport {\n isRefusedByUser,\n willRequestPermission,\n} from \"@api/secure-channel/utils\";\nimport { bufferToHexaString, hexaStringToBuffer } from \"@api/utils/HexaString\";\nimport {\n SecureChannelError,\n type WebSocketConnectionError,\n} from \"@internal/secure-channel/model/Errors\";\n\nexport type ConnectToSecureChannelTaskArgs = {\n connection: Either<WebSocketConnectionError, WebSocket>;\n};\n\nexport class ConnectToSecureChannelTask {\n private readonly _connection: WebSocket;\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: ConnectToSecureChannelTaskArgs,\n ) {\n if (this._args.connection.isRight()) {\n this._connection = this._args.connection.extract();\n } else {\n throw new SecureChannelError(\n `Invalid WebSocket connection: ${String(this._args.connection.extract())}`,\n );\n }\n }\n\n run(): Observable<SecureChannelEvent> {\n const reenableRefresher = this._api.disableRefresher(\n \"connectToSecureChannel\",\n );\n\n const obs = new Observable<SecureChannelEvent>((subscriber) => {\n let unsubscribed: boolean = false;\n let inBulkMode = false;\n let communicationFinished = false;\n let deviceError: SecureChannelError | null = null;\n let waitingForUserAction = false;\n\n this._connection.onopen = () => {\n subscriber.next({\n type: SecureChannelEventType.Opened,\n });\n };\n\n this._connection.onerror = (error) => {\n // When the bulk sending is in progress, network error is ignored\n if (inBulkMode) {\n return;\n }\n\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: error.message,\n }),\n );\n };\n\n this._connection.onclose = () => {\n // When the bulk sending is in progress, network event is ignored\n if (inBulkMode) {\n return;\n }\n\n if (communicationFinished) {\n subscriber.next({\n type: SecureChannelEventType.Closed,\n });\n subscriber.complete();\n } else {\n subscriber.error(\n new SecureChannelError(\n deviceError ?? {\n url: this._connection.url,\n errorMessage: \"Connection closed unexpectedly\",\n },\n ),\n );\n }\n };\n\n this._connection.onmessage = async (event) => {\n // When unsubscribed, ignore the message\n if (unsubscribed) {\n return;\n }\n deviceError = null;\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const input: InMessageType = JSON.parse(String(event.data));\n\n switch (input.query) {\n case InMessageQueryEnum.EXCHANGE: {\n const { nonce } = input;\n\n if (Array.isArray(input.data)) {\n subscriber.error(\n new SecureChannelError(\n `${InMessageQueryEnum.EXCHANGE} data type should not be Array`,\n ),\n );\n break;\n }\n\n const apdu = hexaStringToBuffer(input.data);\n\n if (apdu === null || apdu.length < 5) {\n subscriber.error(\n new SecureChannelError(\n `Received invalid APDU data: ${input.data}`,\n ),\n );\n break;\n }\n\n subscriber.next({\n type: SecureChannelEventType.PreExchange,\n payload: { nonce, apdu },\n });\n\n if (\n willRequestPermission(apdu) &&\n !this.isSecureConnectionAllowed()\n ) {\n waitingForUserAction = true;\n subscriber.next({\n type: SecureChannelEventType.PermissionRequested,\n });\n }\n\n const response = await this._api.sendApdu(apdu);\n\n if (unsubscribed) {\n return;\n }\n\n response.caseOf({\n Left: (error) => {\n subscriber.error(new SecureChannelError(error));\n },\n Right: (apduResponse: ApduResponse) => {\n let outMessageResponse: OutMessageResponseEnum;\n /**\n * | Status Code | Description | Event Emitted |\n * |-------------|------------------------------------|------------------------------------|\n * | 0x9000 | Success | SecureChannelEventEnum.Exchange |\n * | 0x5515 | Device is locked | Error |\n * | 0x5501 | User refused on the device | Error |\n * | 0x6985 | Condition of use not satisfied | Error |\n */\n // Success response\n if (CommandUtils.isSuccessResponse(apduResponse)) {\n outMessageResponse = OutMessageResponseEnum.SUCCESS;\n // Emit event for the exchange\n subscriber.next({\n type: SecureChannelEventType.Exchange,\n payload: {\n nonce,\n apdu,\n data: apduResponse.data,\n status: apduResponse.statusCode,\n },\n });\n } else {\n outMessageResponse = OutMessageResponseEnum.ERROR;\n\n deviceError = new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Invalid status code: ${bufferToHexaString(\n apduResponse.statusCode,\n )}`,\n });\n\n // Device is locked\n if (CommandUtils.isLockedDeviceResponse(apduResponse)) {\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Device is locked`,\n }),\n );\n return;\n }\n\n // User refused the permission\n if (\n isRefusedByUser(apduResponse.statusCode) &&\n waitingForUserAction\n ) {\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: \"User refused on the device\",\n }),\n );\n return;\n }\n }\n\n if (waitingForUserAction) {\n subscriber.next({\n type: SecureChannelEventType.PermissionGranted,\n });\n waitingForUserAction = false;\n }\n\n // Send the message back to the server\n const message: OutMessageType = {\n nonce,\n response: outMessageResponse,\n data: bufferToHexaString(apduResponse.data).slice(2),\n };\n this._connection.send(JSON.stringify(message));\n },\n });\n break;\n }\n case InMessageQueryEnum.BULK: {\n inBulkMode = true;\n this._connection.close();\n\n if (!Array.isArray(input.data) || input.data.length === 0) {\n subscriber.error(\n new SecureChannelError(\"Invalid bulk data received\"),\n );\n break;\n }\n\n const apdus = input.data.reduce(\n (acc: Array<Uint8Array>, cur: string) => {\n const apdu = hexaStringToBuffer(cur);\n return apdu === null ? acc : [...acc, apdu];\n },\n [],\n );\n\n for (let i = 0, len = apdus.length; i < len; i++) {\n await this._api.sendApdu(apdus[i]!);\n if (unsubscribed) {\n subscriber.error(\n new SecureChannelError(\n \"Bulk sending cancelled by unsubscribing\",\n ),\n );\n break;\n }\n subscriber.next({\n type: SecureChannelEventType.Progress,\n payload: {\n progress: +Number((i + 1) / len).toFixed(2),\n index: i,\n total: len,\n },\n });\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.SUCCESS: {\n // Ignore success message when in bulk mode\n if (inBulkMode) {\n break;\n }\n // Emit the result if there is any\n const payload = input.result ?? input.data;\n if (payload) {\n subscriber.next({\n type: SecureChannelEventType.Result,\n payload: payload ?? \"\",\n });\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.WARNING: {\n // Ignore warning message when in bulk mode\n if (inBulkMode) {\n break;\n }\n subscriber.next({\n type: SecureChannelEventType.Warning,\n payload: { message: String(input.data) },\n });\n break;\n }\n case InMessageQueryEnum.ERROR: {\n if (inBulkMode) {\n break;\n }\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: String(input.data),\n }),\n );\n }\n }\n } catch (error) {\n deviceError = new SecureChannelError(error);\n subscriber.error(deviceError);\n }\n };\n\n return () => {\n reenableRefresher();\n unsubscribed = true;\n // Close the connection if it is open when unsubscribing\n if (this._connection.readyState === WebSocket.OPEN) {\n this._connection.close();\n }\n };\n });\n\n return obs;\n }\n\n /**\n * Determines if a secure connection is already allowed based on the current device session state.\n *\n * @returns {boolean} `true` if a secure connection is allowed, otherwise `false`.\n */\n isSecureConnectionAllowed(): boolean {\n const deviceSessionState = this._api.getDeviceSessionState();\n return (\n \"isSecureConnectionAllowed\" in deviceSessionState &&\n deviceSessionState.isSecureConnectionAllowed\n );\n }\n}\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AAUA,EAAM,KAClCY,GACFpB,EAAW,KAAK,CACd,KAAM,yBAAuB,OAC7B,QAASoB,GAAW,EACtB,CAAC,EAEHjB,EAAwB,GACxBH,EAAW,SAAS,EACpB,KACF,CACA,KAAK,qBAAmB,QAAS,CAE/B,GAAIE,EACF,MAEFF,EAAW,KAAK,CACd,KAAM,yBAAuB,QAC7B,QAAS,CAAE,QAAS,OAAOQ,EAAM,IAAI,CAAE,CACzC,CAAC,EACD,KACF,CACA,KAAK,qBAAmB,MAAO,CAC7B,GAAIN,EACF,MAEFF,EAAW,MACT,IAAI,qBAAmB,CACrB,IAAK,KAAK,YAAY,IACtB,aAAc,OAAOQ,EAAM,IAAI,CACjC,CAAC,CACH,CACF,CACF,CACF,OAASF,EAAO,CACdF,EAAc,IAAI,qBAAmBE,CAAK,EAC1CN,EAAW,MAAMI,CAAW,CAC9B,EACF,EAEO,IAAM,CACXL,EAAkB,EAClBE,EAAe,GAEX,KAAK,YAAY,aAAe,EAAAoB,QAAU,MAC5C,KAAK,YAAY,MAAM,CAE3B,CACF,CAAC,CAGH,CAOA,2BAAqC,CACnC,MAAMC,EAAqB,KAAK,KAAK,sBAAsB,EAC3D,MACE,8BAA+BA,GAC/BA,EAAmB,yBAEvB,CACF",
6
6
  "names": ["ConnectToSecureChannelTask_exports", "__export", "ConnectToSecureChannelTask", "__toCommonJS", "import_isomorphic_ws", "import_rxjs", "import_CommandUtils", "import_types", "import_utils", "import_HexaString", "import_Errors", "_api", "_args", "reenableRefresher", "subscriber", "unsubscribed", "inBulkMode", "communicationFinished", "deviceError", "waitingForUserAction", "error", "event", "input", "nonce", "apdu", "response", "apduResponse", "outMessageResponse", "message", "apdus", "acc", "cur", "i", "len", "payload", "WebSocket", "deviceSessionState"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var o=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var P=(r,e)=>{for(var t in e)o(r,t,{get:e[t],enumerable:!0})},h=(r,e,t,d)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of u(e))!x.call(r,s)&&s!==t&&o(r,s,{get:()=>e[s],enumerable:!(d=c(e,s))||d.enumerable});return r};var A=r=>h(o({},"__esModule",{value:!0}),r);var R={};P(R,{InMessageQueryEnum:()=>l,OutMessageResponseEnum:()=>g,SecureChannelEventType:()=>y,SecureChannelOperationEnum:()=>i});module.exports=A(R);var i=(a=>(a.GenuineCheck="GenuineCheck",a.ListInstalledApps="ListInstalledApps",a.UpdateMcu="UpdateMcu",a.UpdateFirmware="UpdateFirmware",a.InstallApp="InstallApp",a.UninstallApp="UninstallApp",a))(i||{}),l=(p=>(p.EXCHANGE="exchange",p.BULK="bulk",p.ERROR="error",p.WARNING="warning",p.SUCCESS="success",p))(l||{}),g=(t=>(t.SUCCESS="success",t.ERROR="error",t))(g||{}),y=(n=>(n.Opened="opened",n.Closed="closed",n.PermissionRequested="permission-requested",n.PermissionGranted="permission-granted",n.PreExchange="pre-exchange",n.Exchange="exchange",n.Progress="progress",n.Warning="warning",n.Result="result",n))(y||{});0&&(module.exports={InMessageQueryEnum,OutMessageResponseEnum,SecureChannelEventType,SecureChannelOperationEnum});
1
+ "use strict";var o=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var P=(r,e)=>{for(var t in e)o(r,t,{get:e[t],enumerable:!0})},h=(r,e,t,d)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of u(e))!x.call(r,s)&&s!==t&&o(r,s,{get:()=>e[s],enumerable:!(d=c(e,s))||d.enumerable});return r};var A=r=>h(o({},"__esModule",{value:!0}),r);var U={};P(U,{InMessageQueryEnum:()=>i,OutMessageResponseEnum:()=>g,SecureChannelEventType:()=>y,SecureChannelOperationEnum:()=>l});module.exports=A(U);var l=(a=>(a.GenuineCheck="GenuineCheck",a.ListInstalledApps="ListInstalledApps",a.UpdateMcu="UpdateMcu",a.UpdateFirmware="UpdateFirmware",a.InstallApp="InstallApp",a.UninstallApp="UninstallApp",a))(l||{}),i=(p=>(p.EXCHANGE="exchange",p.BULK="bulk",p.ERROR="error",p.WARNING="warning",p.SUCCESS="success",p))(i||{}),g=(t=>(t.SUCCESS="success",t.ERROR="error",t))(g||{}),y=(n=>(n.Opened="opened",n.Closed="closed",n.PermissionRequested="permission-requested",n.PermissionGranted="permission-granted",n.PreExchange="pre-exchange",n.Exchange="exchange",n.Progress="progress",n.Warning="warning",n.Result="result",n))(y||{});0&&(module.exports={InMessageQueryEnum,OutMessageResponseEnum,SecureChannelEventType,SecureChannelOperationEnum});
2
2
  //# sourceMappingURL=types.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/secure-channel/task/types.ts"],
4
- "sourcesContent": ["export enum SecureChannelOperationEnum {\n GenuineCheck = \"GenuineCheck\",\n ListInstalledApps = \"ListInstalledApps\",\n UpdateMcu = \"UpdateMcu\",\n UpdateFirmware = \"UpdateFirmware\",\n InstallApp = \"InstallApp\",\n UninstallApp = \"UninstallApp\",\n}\n\n/**\n * The message that will be received from the server by the secure channel.\n */\nexport type InMessageType = {\n uuid: string;\n session: string;\n query: InMessageQueryEnum;\n nonce: number;\n data: string | Array<string>;\n result?: unknown;\n};\n\nexport enum InMessageQueryEnum {\n EXCHANGE = \"exchange\",\n BULK = \"bulk\",\n ERROR = \"error\",\n WARNING = \"warning\",\n SUCCESS = \"success\",\n}\n\n/**\n * The message that will be sent to the server by the secure channel.\n */\nexport type OutMessageType = {\n nonce: number;\n response: OutMessageResponseEnum;\n data: string;\n};\n\nexport enum OutMessageResponseEnum {\n SUCCESS = \"success\",\n ERROR = \"error\",\n}\n\n/**\n * The all event types that can be emitted to the client by the secure channel.\n *\n */\nexport enum SecureChannelEventType {\n Opened = \"opened\",\n Closed = \"closed\",\n PermissionRequested = \"permission-requested\",\n PermissionGranted = \"permission-granted\",\n PreExchange = \"pre-exchange\",\n Exchange = \"exchange\",\n Progress = \"progress\",\n Warning = \"warning\",\n Result = \"result\",\n}\n\n/**\n * The possible payload that will be sent to the client when a secure channel event occurs.\n */\nexport type SecureChannelEventPayload = {\n PreExchange: { nonce: number; apdu: Uint8Array };\n Exchange: {\n nonce: number;\n apdu: Uint8Array;\n data: Uint8Array;\n status: Uint8Array;\n };\n Progress: { progress: number; index: number; total: number };\n Warning: { message: string };\n Result: string | Record<string, unknown>;\n};\n\n/**\n * The event type that will be emitted to the client when a secure channel event occurs.\n */\nexport type SecureChannelEvent =\n | {\n type: SecureChannelEventType.Opened;\n }\n | {\n type: SecureChannelEventType.Closed;\n }\n | {\n type: SecureChannelEventType.PermissionRequested;\n }\n | {\n type: SecureChannelEventType.PermissionGranted;\n }\n | {\n type: SecureChannelEventType.PreExchange;\n payload: SecureChannelEventPayload[\"PreExchange\"];\n }\n | {\n type: SecureChannelEventType.Exchange;\n payload: SecureChannelEventPayload[\"Exchange\"];\n }\n | {\n type: SecureChannelEventType.Progress;\n payload: SecureChannelEventPayload[\"Progress\"];\n }\n | {\n type: SecureChannelEventType.Warning;\n payload: SecureChannelEventPayload[\"Warning\"];\n }\n | {\n type: SecureChannelEventType.Result;\n payload: SecureChannelEventPayload[\"Result\"];\n };\n"],
4
+ "sourcesContent": ["export enum SecureChannelOperationEnum {\n GenuineCheck = \"GenuineCheck\",\n ListInstalledApps = \"ListInstalledApps\",\n UpdateMcu = \"UpdateMcu\",\n UpdateFirmware = \"UpdateFirmware\",\n InstallApp = \"InstallApp\",\n UninstallApp = \"UninstallApp\",\n}\n\n/**\n * The message that will be received from the server by the secure channel.\n */\nexport type InMessageType = {\n uuid: string;\n session: string;\n query: InMessageQueryEnum;\n nonce: number;\n data: string | Array<string>;\n result?: unknown;\n};\n\nexport enum InMessageQueryEnum {\n EXCHANGE = \"exchange\",\n BULK = \"bulk\",\n ERROR = \"error\",\n WARNING = \"warning\",\n SUCCESS = \"success\",\n}\n\n/**\n * The message that will be sent to the server by the secure channel.\n */\nexport type OutMessageType = {\n nonce: number;\n response: OutMessageResponseEnum;\n data: string;\n};\n\nexport enum OutMessageResponseEnum {\n SUCCESS = \"success\",\n ERROR = \"error\",\n}\n\n/**\n * The all event types that can be emitted to the client by the secure channel.\n *\n */\nexport enum SecureChannelEventType {\n Opened = \"opened\",\n Closed = \"closed\",\n PermissionRequested = \"permission-requested\",\n PermissionGranted = \"permission-granted\",\n PreExchange = \"pre-exchange\",\n Exchange = \"exchange\",\n Progress = \"progress\",\n Warning = \"warning\",\n Result = \"result\",\n}\n\n/**\n * The possible payload that will be sent to the client when a secure channel event occurs.\n */\nexport type SecureChannelEventPayload = {\n PreExchange: { nonce: number; apdu: Uint8Array };\n Exchange: {\n nonce: number;\n apdu: Uint8Array;\n data: Uint8Array;\n status: Uint8Array;\n };\n Progress: { progress: number; index: number; total: number };\n Warning: { message: string };\n Result: unknown;\n};\n\n/**\n * The event type that will be emitted to the client when a secure channel event occurs.\n */\nexport type SecureChannelEvent =\n | {\n type: SecureChannelEventType.Opened;\n }\n | {\n type: SecureChannelEventType.Closed;\n }\n | {\n type: SecureChannelEventType.PermissionRequested;\n }\n | {\n type: SecureChannelEventType.PermissionGranted;\n }\n | {\n type: SecureChannelEventType.PreExchange;\n payload: SecureChannelEventPayload[\"PreExchange\"];\n }\n | {\n type: SecureChannelEventType.Exchange;\n payload: SecureChannelEventPayload[\"Exchange\"];\n }\n | {\n type: SecureChannelEventType.Progress;\n payload: SecureChannelEventPayload[\"Progress\"];\n }\n | {\n type: SecureChannelEventType.Warning;\n payload: SecureChannelEventPayload[\"Warning\"];\n }\n | {\n type: SecureChannelEventType.Result;\n payload: SecureChannelEventPayload[\"Result\"];\n };\n"],
5
5
  "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,2BAAAC,EAAA,2BAAAC,EAAA,+BAAAC,IAAA,eAAAC,EAAAN,GAAO,IAAKK,OACVA,EAAA,aAAe,eACfA,EAAA,kBAAoB,oBACpBA,EAAA,UAAY,YACZA,EAAA,eAAiB,iBACjBA,EAAA,WAAa,aACbA,EAAA,aAAe,eANLA,OAAA,IAqBAH,OACVA,EAAA,SAAW,WACXA,EAAA,KAAO,OACPA,EAAA,MAAQ,QACRA,EAAA,QAAU,UACVA,EAAA,QAAU,UALAA,OAAA,IAiBAC,OACVA,EAAA,QAAU,UACVA,EAAA,MAAQ,QAFEA,OAAA,IASAC,OACVA,EAAA,OAAS,SACTA,EAAA,OAAS,SACTA,EAAA,oBAAsB,uBACtBA,EAAA,kBAAoB,qBACpBA,EAAA,YAAc,eACdA,EAAA,SAAW,WACXA,EAAA,SAAW,WACXA,EAAA,QAAU,UACVA,EAAA,OAAS,SATCA,OAAA",
6
6
  "names": ["types_exports", "__export", "InMessageQueryEnum", "OutMessageResponseEnum", "SecureChannelEventType", "SecureChannelOperationEnum", "__toCommonJS"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ "use strict";var u=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var r=Object.prototype.hasOwnProperty;var x=(t,p,T,n)=>{if(p&&typeof p=="object"||typeof p=="function")for(let e of o(p))!r.call(t,e)&&e!==T&&u(t,e,{get:()=>p[e],enumerable:!(n=i(p,e))||n.enumerable});return t};var y=t=>x(u({},"__esModule",{value:!0}),t);var I={};module.exports=y(I);
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/api/secure-channel/types.ts"],
4
+ "sourcesContent": ["export type Input<T> = { input: T };\n"],
5
+ "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
+ "names": ["types_exports", "__toCommonJS"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var c=(t,e,s,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of n(e))!a.call(t,r)&&r!==s&&o(t,r,{get:()=>e[r],enumerable:!(p=i(e,r))||p.enumerable});return t};var m=t=>c(o({},"__esModule",{value:!0}),t);var d={};module.exports=m(d);
1
+ "use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var c=(t,e,s,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of n(e))!a.call(t,r)&&r!==s&&o(t,r,{get:()=>e[r],enumerable:!(p=i(e,r))||p.enumerable});return t};var d=t=>c(o({},"__esModule",{value:!0}),t);var m={};module.exports=d(m);
2
2
  //# sourceMappingURL=types.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/types.ts"],
4
- "sourcesContent": ["export type { OpenAppErrorCodes } from \"./command/os/OpenAppCommand\";\nexport type { CommandErrors } from \"./command/utils/CommandErrors\";\nexport type { DeviceId } from \"./device/DeviceModel\";\nexport type { ConnectionType } from \"./discovery/ConnectionType\";\nexport type { CommandErrorArgs } from \"./Error\";\nexport type { LogSubscriberOptions } from \"./logger-subscriber/model/LogSubscriberOptions\";\nexport type { DiscoveredDevice } from \"./transport/model/DiscoveredDevice\";\nexport type {\n Transport,\n TransportArgs,\n TransportFactory,\n} from \"./transport/model/Transport\";\nexport type { TransportIdentifier } from \"./transport/model/TransportIdentifier\";\nexport type { ApduBuilderArgs } from \"@api/apdu/utils/ApduBuilder\";\nexport type { Command } from \"@api/command/Command\";\nexport type {\n CommandErrorResult,\n CommandResult,\n CommandSuccessResult,\n} from \"@api/command/model/CommandResult\";\nexport type { SendCommandUseCaseArgs } from \"@api/command/use-case/SendCommandUseCase\";\nexport type { DeviceModelId } from \"@api/device/DeviceModel\";\nexport {\n type DeviceAction,\n type DeviceActionIntermediateValue,\n type ExecuteDeviceActionReturnType,\n} from \"@api/device-action/DeviceAction\";\nexport {\n type GetDeviceStatusDAError,\n type GetDeviceStatusDAInput,\n type GetDeviceStatusDAIntermediateValue,\n type GetDeviceStatusDAOutput,\n type GetDeviceStatusDAState,\n} from \"@api/device-action/os/GetDeviceStatus/types\";\nexport {\n type GoToDashboardDAError,\n type GoToDashboardDAInput,\n type GoToDashboardDAIntermediateValue,\n type GoToDashboardDAOutput,\n type GoToDashboardDAState,\n} from \"@api/device-action/os/GoToDashboard/types\";\nexport {\n type ListAppsDAError,\n type ListAppsDAInput,\n type ListAppsDAIntermediateValue,\n type ListAppsDAOutput,\n type ListAppsDAState,\n} from \"@api/device-action/os/ListApps/types\";\nexport {\n type ListAppsWithMetadataDAError,\n type ListAppsWithMetadataDAInput,\n type ListAppsWithMetadataDAIntermediateValue,\n type ListAppsWithMetadataDAOutput,\n type ListAppsWithMetadataDAState,\n} from \"@api/device-action/os/ListAppsWithMetadata/types\";\nexport {\n type OpenAppDAError,\n type OpenAppDAInput,\n type OpenAppDAIntermediateValue,\n type OpenAppDAOutput,\n type OpenAppDARequiredInteraction,\n type OpenAppDAState,\n} from \"@api/device-action/os/OpenAppDeviceAction/types\";\nexport {\n type SendCommandInAppDAError,\n type SendCommandInAppDAInput,\n type SendCommandInAppDAIntermediateValue,\n type SendCommandInAppDAOutput,\n} from \"@api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes\";\nexport type { ExecuteDeviceActionUseCaseArgs } from \"@api/device-action/use-case/ExecuteDeviceActionUseCase\";\nexport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nexport { type DeviceModelDataSource } from \"@api/device-model/data/DeviceModelDataSource\";\nexport type { DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nexport { type ApduReceiverService } from \"@api/device-session/service/ApduReceiverService\";\nexport { type ApduReceiverServiceFactory } from \"@api/device-session/service/ApduReceiverService\";\nexport { type ApduSenderServiceFactory } from \"@api/device-session/service/ApduSenderService\";\nexport { type ApduSenderService } from \"@api/device-session/service/ApduSenderService\";\nexport type { DeviceSessionId } from \"@api/device-session/types\";\nexport type { DmkConfig } from \"@api/DmkConfig\";\nexport type { DmkError } from \"@api/Error\";\nexport type { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nexport type {\n LoggerSubscriberService,\n LogParams,\n} from \"@api/logger-subscriber/service/LoggerSubscriberService\";\nexport {\n type GenuineCheckDAError,\n type GenuineCheckDAInput,\n type GenuineCheckDAIntermediateValue,\n type GenuineCheckDAOutput,\n type GenuineCheckDARequiredInteraction,\n type GenuineCheckDAState,\n} from \"@api/secure-channel/device-action/GenuineCheck/types\";\nexport { type DeviceApduSender } from \"@api/transport/model/DeviceApduSender\";\nexport {\n type DeviceConnection,\n type DisconnectHandler,\n type SendApduFnType,\n} from \"@api/transport/model/DeviceConnection\";\nexport { type TransportDiscoveredDevice } from \"@api/transport/model/TransportDiscoveredDevice\";\nexport type { HexaString } from \"@api/utils/HexaString\";\nexport type { ConnectUseCaseArgs } from \"@internal/discovery/use-case/ConnectUseCase\";\nexport type { DisconnectUseCaseArgs } from \"@internal/discovery/use-case/DisconnectUseCase\";\nexport type { GetConnectedDeviceUseCaseArgs } from \"@internal/discovery/use-case/GetConnectedDeviceUseCase\";\nexport type { StartDiscoveringUseCaseArgs } from \"@internal/discovery/use-case/StartDiscoveringUseCase\";\nexport type { SendApduUseCaseArgs } from \"@internal/send/use-case/SendApduUseCase\";\n"],
4
+ "sourcesContent": ["export type { OpenAppErrorCodes } from \"./command/os/OpenAppCommand\";\nexport type { CommandErrors } from \"./command/utils/CommandErrors\";\nexport type { DeviceId } from \"./device/DeviceModel\";\nexport type { ConnectionType } from \"./discovery/ConnectionType\";\nexport type { CommandErrorArgs } from \"./Error\";\nexport type { LogSubscriberOptions } from \"./logger-subscriber/model/LogSubscriberOptions\";\nexport type { DiscoveredDevice } from \"./transport/model/DiscoveredDevice\";\nexport type {\n Transport,\n TransportArgs,\n TransportFactory,\n} from \"./transport/model/Transport\";\nexport type { TransportIdentifier } from \"./transport/model/TransportIdentifier\";\nexport type { ApduBuilderArgs } from \"@api/apdu/utils/ApduBuilder\";\nexport type { Command } from \"@api/command/Command\";\nexport type {\n CommandErrorResult,\n CommandResult,\n CommandSuccessResult,\n} from \"@api/command/model/CommandResult\";\nexport type { SendCommandUseCaseArgs } from \"@api/command/use-case/SendCommandUseCase\";\nexport type { DeviceModelId } from \"@api/device/DeviceModel\";\nexport {\n type DeviceAction,\n type DeviceActionIntermediateValue,\n type ExecuteDeviceActionReturnType,\n} from \"@api/device-action/DeviceAction\";\nexport {\n type GetDeviceStatusDAError,\n type GetDeviceStatusDAInput,\n type GetDeviceStatusDAIntermediateValue,\n type GetDeviceStatusDAOutput,\n type GetDeviceStatusDAState,\n} from \"@api/device-action/os/GetDeviceStatus/types\";\nexport {\n type GoToDashboardDAError,\n type GoToDashboardDAInput,\n type GoToDashboardDAIntermediateValue,\n type GoToDashboardDAOutput,\n type GoToDashboardDAState,\n} from \"@api/device-action/os/GoToDashboard/types\";\nexport {\n type ListAppsDAError,\n type ListAppsDAInput,\n type ListAppsDAIntermediateValue,\n type ListAppsDAOutput,\n type ListAppsDAState,\n} from \"@api/device-action/os/ListApps/types\";\nexport {\n type ListAppsWithMetadataDAError,\n type ListAppsWithMetadataDAInput,\n type ListAppsWithMetadataDAIntermediateValue,\n type ListAppsWithMetadataDAOutput,\n type ListAppsWithMetadataDAState,\n} from \"@api/device-action/os/ListAppsWithMetadata/types\";\nexport {\n type OpenAppDAError,\n type OpenAppDAInput,\n type OpenAppDAIntermediateValue,\n type OpenAppDAOutput,\n type OpenAppDARequiredInteraction,\n type OpenAppDAState,\n} from \"@api/device-action/os/OpenAppDeviceAction/types\";\nexport {\n type SendCommandInAppDAError,\n type SendCommandInAppDAInput,\n type SendCommandInAppDAIntermediateValue,\n type SendCommandInAppDAOutput,\n} from \"@api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes\";\nexport type { ExecuteDeviceActionUseCaseArgs } from \"@api/device-action/use-case/ExecuteDeviceActionUseCase\";\nexport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nexport { type DeviceModelDataSource } from \"@api/device-model/data/DeviceModelDataSource\";\nexport type { DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nexport { type ApduReceiverService } from \"@api/device-session/service/ApduReceiverService\";\nexport { type ApduReceiverServiceFactory } from \"@api/device-session/service/ApduReceiverService\";\nexport { type ApduSenderServiceFactory } from \"@api/device-session/service/ApduSenderService\";\nexport { type ApduSenderService } from \"@api/device-session/service/ApduSenderService\";\nexport type { DeviceSessionId } from \"@api/device-session/types\";\nexport type { DmkConfig } from \"@api/DmkConfig\";\nexport type { DmkError } from \"@api/Error\";\nexport type { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nexport type {\n LoggerSubscriberService,\n LogParams,\n} from \"@api/logger-subscriber/service/LoggerSubscriberService\";\nexport {\n type GenuineCheckDAError,\n type GenuineCheckDAInput,\n type GenuineCheckDAIntermediateValue,\n type GenuineCheckDAOutput,\n type GenuineCheckDARequiredInteraction,\n type GenuineCheckDAState,\n} from \"@api/secure-channel/device-action/GenuineCheck/types\";\nexport {\n type ListInstalledAppsDAError,\n type ListInstalledAppsDAInput,\n type ListInstalledAppsDAIntermediateValue,\n type ListInstalledAppsDAOutput,\n type ListInstalledAppsDARequiredInteraction,\n type ListInstalledAppsDAState,\n} from \"@api/secure-channel/device-action/ListInstalledApps/types\";\nexport { type DeviceApduSender } from \"@api/transport/model/DeviceApduSender\";\nexport {\n type DeviceConnection,\n type DisconnectHandler,\n type SendApduFnType,\n} from \"@api/transport/model/DeviceConnection\";\nexport { type TransportDiscoveredDevice } from \"@api/transport/model/TransportDiscoveredDevice\";\nexport type { HexaString } from \"@api/utils/HexaString\";\nexport type { ConnectUseCaseArgs } from \"@internal/discovery/use-case/ConnectUseCase\";\nexport type { DisconnectUseCaseArgs } from \"@internal/discovery/use-case/DisconnectUseCase\";\nexport type { GetConnectedDeviceUseCaseArgs } from \"@internal/discovery/use-case/GetConnectedDeviceUseCase\";\nexport type { StartDiscoveringUseCaseArgs } from \"@internal/discovery/use-case/StartDiscoveringUseCase\";\nexport type { SendApduUseCaseArgs } from \"@internal/send/use-case/SendApduUseCase\";\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["types_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var c=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var y=(n,e)=>{for(var i in e)c(n,i,{get:e[i],enumerable:!0})},A=(n,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of _(e))!C.call(n,t)&&t!==i&&c(n,t,{get:()=>e[t],enumerable:!(r=g(e,t))||r.enumerable});return n};var E=n=>A(c({},"__esModule",{value:!0}),n);var R={};y(R,{DeviceSession:()=>b});module.exports=E(R);var d=require("purify-ts"),p=require("rxjs"),v=require("uuid"),u=require("../../../api/command/utils/CommandUtils"),s=require("../../../api/device/DeviceStatus"),S=require("../../../api/device-session/DeviceSessionState"),l=require("../../../api/Error"),h=require("../../device-session/data/DeviceSessionRefresherConst"),m=require("../../device-session/service/RefresherService"),D=require("./DeviceSessionRefresher");class b{_id;_connectedDevice;_deviceState;_refresher;_refresherService;_managerApiService;_secureChannelService;constructor({connectedDevice:e,id:i=(0,v.v4)()},r,t,a){this._id=i,this._connectedDevice=e,this._deviceState=new p.BehaviorSubject({sessionStateType:S.DeviceSessionStateType.Connected,deviceStatus:s.DeviceStatus.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id}),this._refresher=new D.DeviceSessionRefresher({refreshInterval:h.DEVICE_SESSION_REFRESH_INTERVAL,deviceStatus:s.DeviceStatus.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id,sendApduFn:o=>this.sendApdu(o,{isPolling:!0,triggersDisconnection:!1}),updateStateFn:o=>{const f=this._deviceState.getValue();this.setDeviceSessionState(o(f))}},r("device-session-refresher")),this._refresherService=new m.RefresherService(this._refresher),this._managerApiService=t,this._secureChannelService=a}get id(){return this._id}get connectedDevice(){return this._connectedDevice}get state(){return this._deviceState.asObservable()}setDeviceSessionState(e){this._deviceState.next(e)}async sendApdu(e,i={isPolling:!1,triggersDisconnection:!1}){let r;return i.isPolling||(r=this._refresherService.disableRefresher("sendApdu"),await this.waitUntilReady()),this._deviceState.getValue().deviceStatus===s.DeviceStatus.BUSY?(0,d.Left)(new l.DeviceBusyError):(this.updateDeviceStatus(s.DeviceStatus.BUSY),(await this._connectedDevice.sendApdu(e,i.triggersDisconnection)).ifRight(o=>{u.CommandUtils.isLockedDeviceResponse(o)?this.updateDeviceStatus(s.DeviceStatus.LOCKED):this.updateDeviceStatus(s.DeviceStatus.CONNECTED),!i.isPolling&&r&&r()}).ifLeft(()=>{this.updateDeviceStatus(s.DeviceStatus.CONNECTED),!i.isPolling&&r&&r()}))}async sendCommand(e){const i=e.getApdu();return(await this.sendApdu(i.getRawApdu(),{isPolling:!1,triggersDisconnection:e.triggersDisconnection??!1})).caseOf({Left:t=>{throw t},Right:t=>e.parseResponse(t,this._connectedDevice.deviceModel.id)})}executeDeviceAction(e){const{observable:i,cancel:r}=e._execute({sendApdu:async t=>this.sendApdu(t),sendCommand:async t=>this.sendCommand(t),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:i,cancel:r}}close(){this.updateDeviceStatus(s.DeviceStatus.NOT_CONNECTED),this._deviceState.complete(),this._refresher.stop()}disableRefresher(e){return this._refresherService.disableRefresher(e)}updateDeviceStatus(e){const i=this._deviceState.getValue();this._refresher.setDeviceStatus(e),this._deviceState.next({...i,deviceStatus:e})}async waitUntilReady(){let e;await new Promise(i=>{e=this._deviceState.subscribe(r=>{r.deviceStatus===s.DeviceStatus.CONNECTED&&(e?.unsubscribe(),i())})})}}0&&(module.exports={DeviceSession});
1
+ "use strict";var c=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var y=(n,e)=>{for(var i in e)c(n,i,{get:e[i],enumerable:!0})},A=(n,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of _(e))!C.call(n,t)&&t!==i&&c(n,t,{get:()=>e[t],enumerable:!(r=g(e,t))||r.enumerable});return n};var E=n=>A(c({},"__esModule",{value:!0}),n);var R={};y(R,{DeviceSession:()=>b});module.exports=E(R);var d=require("purify-ts"),p=require("rxjs"),v=require("uuid"),u=require("../../../api/command/utils/CommandUtils"),s=require("../../../api/device/DeviceStatus"),S=require("../../../api/device-session/DeviceSessionState"),l=require("../../../api/Error"),h=require("../../device-session/data/DeviceSessionRefresherConst"),m=require("../../device-session/service/RefresherService"),D=require("./DeviceSessionRefresher");class b{_id;_connectedDevice;_deviceState;_refresher;_refresherService;_managerApiService;_secureChannelService;constructor({connectedDevice:e,id:i=(0,v.v4)()},r,t,a){this._id=i,this._connectedDevice=e,this._deviceState=new p.BehaviorSubject({sessionStateType:S.DeviceSessionStateType.Connected,deviceStatus:s.DeviceStatus.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id}),this._refresher=new D.DeviceSessionRefresher({refreshInterval:h.DEVICE_SESSION_REFRESH_INTERVAL,deviceStatus:s.DeviceStatus.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id,sendApduFn:o=>this.sendApdu(o,{isPolling:!0,triggersDisconnection:!1}),updateStateFn:o=>{const f=this._deviceState.getValue();this.setDeviceSessionState(o(f))}},r("device-session-refresher")),this._refresherService=new m.RefresherService(this._refresher),this._managerApiService=t,this._secureChannelService=a}get id(){return this._id}get connectedDevice(){return this._connectedDevice}get state(){return this._deviceState.asObservable()}setDeviceSessionState(e){this._deviceState.next(e)}async sendApdu(e,i={isPolling:!1,triggersDisconnection:!1}){let r;return i.isPolling||(r=this._refresherService.disableRefresher("sendApdu"),await this.waitUntilReady()),this._deviceState.getValue().deviceStatus===s.DeviceStatus.BUSY?(0,d.Left)(new l.DeviceBusyError):(this.updateDeviceStatus(s.DeviceStatus.BUSY),(await this._connectedDevice.sendApdu(e,i.triggersDisconnection)).ifRight(o=>{u.CommandUtils.isLockedDeviceResponse(o)?this.updateDeviceStatus(s.DeviceStatus.LOCKED):this.updateDeviceStatus(s.DeviceStatus.CONNECTED),!i.isPolling&&r&&r()}).ifLeft(()=>{this.updateDeviceStatus(s.DeviceStatus.CONNECTED),!i.isPolling&&r&&r()}))}async sendCommand(e){const i=e.getApdu();return(await this.sendApdu(i.getRawApdu(),{isPolling:!1,triggersDisconnection:e.triggersDisconnection??!1})).caseOf({Left:t=>{throw t},Right:t=>e.parseResponse(t,this._connectedDevice.deviceModel.id)})}executeDeviceAction(e){const{observable:i,cancel:r}=e._execute({sendApdu:async t=>this.sendApdu(t),sendCommand:async t=>this.sendCommand(t),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:i,cancel:r}}close(){this.updateDeviceStatus(s.DeviceStatus.NOT_CONNECTED),this._deviceState.complete(),this._refresher.stop()}disableRefresher(e){return this._refresherService.disableRefresher(e)}updateDeviceStatus(e){const i=this._deviceState.getValue();this._refresher.setDeviceStatus(e),this._deviceState.next({...i,deviceStatus:e})}async waitUntilReady(){let e;await new Promise(i=>{e=this._deviceState.subscribe(r=>{[s.DeviceStatus.LOCKED,s.DeviceStatus.CONNECTED].includes(r.deviceStatus)&&(e?.unsubscribe(),i())})})}}0&&(module.exports={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, Left } from \"purify-ts\";\nimport { BehaviorSubject, type Subscription } 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 { DeviceBusyError, type DmkError } from \"@api/Error\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { type TransportConnectedDevice } from \"@api/transport/model/TransportConnectedDevice\";\nimport { DEVICE_SESSION_REFRESH_INTERVAL } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\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 { DeviceSessionRefresher } from \"./DeviceSessionRefresher\";\n\nexport type SessionConstructorArgs = {\n connectedDevice: TransportConnectedDevice;\n id?: DeviceSessionId;\n};\n\ntype SendApduOptions = {\n isPolling?: boolean;\n triggersDisconnection?: boolean;\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 _refresher: DeviceSessionRefresher;\n private readonly _refresherService: RefresherService;\n private readonly _managerApiService: ManagerApiService;\n private readonly _secureChannelService: SecureChannelService;\n\n constructor(\n { connectedDevice, id = uuidv4() }: SessionConstructorArgs,\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n managerApiService: ManagerApiService,\n secureChannelService: SecureChannelService,\n ) {\n this._id = id;\n this._connectedDevice = connectedDevice;\n this._deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\n });\n this._refresher = new DeviceSessionRefresher(\n {\n refreshInterval: DEVICE_SESSION_REFRESH_INTERVAL,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\n sendApduFn: (rawApdu: Uint8Array) =>\n this.sendApdu(rawApdu, {\n isPolling: true,\n triggersDisconnection: false,\n }),\n updateStateFn: (callback) => {\n const state = this._deviceState.getValue();\n this.setDeviceSessionState(callback(state));\n },\n },\n loggerModuleFactory(\"device-session-refresher\"),\n );\n this._refresherService = new RefresherService(this._refresher);\n this._managerApiService = managerApiService;\n this._secureChannelService = secureChannelService;\n }\n\n public get id() {\n return this._id;\n }\n\n public get connectedDevice() {\n return this._connectedDevice;\n }\n\n public get state() {\n return this._deviceState.asObservable();\n }\n\n public setDeviceSessionState(state: DeviceSessionState) {\n this._deviceState.next(state);\n }\n\n public async sendApdu(\n rawApdu: Uint8Array,\n options: SendApduOptions = {\n isPolling: false,\n triggersDisconnection: false,\n },\n ): Promise<Either<DmkError, ApduResponse>> {\n let reenableRefresher: () => void;\n if (!options.isPolling) {\n reenableRefresher = this._refresherService.disableRefresher(\"sendApdu\");\n await this.waitUntilReady();\n }\n\n const sessionState = this._deviceState.getValue();\n if (sessionState.deviceStatus === DeviceStatus.BUSY) {\n return Left(new DeviceBusyError());\n }\n\n this.updateDeviceStatus(DeviceStatus.BUSY);\n\n const errorOrResponse = await this._connectedDevice.sendApdu(\n rawApdu,\n options.triggersDisconnection,\n );\n\n return errorOrResponse\n .ifRight((response: ApduResponse) => {\n if (CommandUtils.isLockedDeviceResponse(response)) {\n this.updateDeviceStatus(DeviceStatus.LOCKED);\n } else {\n this.updateDeviceStatus(DeviceStatus.CONNECTED);\n }\n\n if (!options.isPolling && reenableRefresher) {\n reenableRefresher();\n }\n })\n .ifLeft(() => {\n this.updateDeviceStatus(DeviceStatus.CONNECTED);\n\n if (!options.isPolling && reenableRefresher) {\n reenableRefresher();\n }\n });\n }\n\n public async sendCommand<Response, Args, ErrorStatusCodes>(\n command: Command<Response, Args, ErrorStatusCodes>,\n ): Promise<CommandResult<Response, ErrorStatusCodes>> {\n const apdu = command.getApdu();\n const response = await this.sendApdu(apdu.getRawApdu(), {\n isPolling: false,\n triggersDisconnection: command.triggersDisconnection ?? false,\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 Error extends DmkError,\n IntermediateValue extends DeviceActionIntermediateValue,\n >(\n deviceAction: DeviceAction<Output, Input, Error, IntermediateValue>,\n ): ExecuteDeviceActionReturnType<Output, Error, 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 ) => this.sendCommand(command),\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\n return {\n observable,\n cancel,\n };\n }\n\n public close() {\n this.updateDeviceStatus(DeviceStatus.NOT_CONNECTED);\n this._deviceState.complete();\n this._refresher.stop();\n }\n\n public disableRefresher(id: string): () => void {\n return this._refresherService.disableRefresher(id);\n }\n\n private updateDeviceStatus(deviceStatus: DeviceStatus) {\n const sessionState = this._deviceState.getValue();\n this._refresher.setDeviceStatus(deviceStatus);\n this._deviceState.next({\n ...sessionState,\n deviceStatus,\n });\n }\n\n private async waitUntilReady() {\n let deviceStateSub: Subscription;\n\n await new Promise<void>((resolve) => {\n deviceStateSub = this._deviceState.subscribe((state) => {\n if (state.deviceStatus === DeviceStatus.CONNECTED) {\n deviceStateSub?.unsubscribe();\n resolve();\n }\n });\n });\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkC,qBAClCC,EAAmD,gBACnDC,EAA6B,gBAI7BC,EAA6B,2CAC7BC,EAA6B,oCAO7BC,EAGO,kDAEPC,EAA+C,sBAG/CC,EAAgD,qEAChDC,EAAiC,6DAIjCC,EAAuC,oCAehC,MAAMX,CAAc,CACR,IACA,iBACA,aACA,WACA,kBACA,mBACA,sBAEjB,YACE,CAAE,gBAAAY,EAAiB,GAAAC,KAAK,EAAAC,IAAO,CAAE,EACjCC,EACAC,EACAC,EACA,CACA,KAAK,IAAMJ,EACX,KAAK,iBAAmBD,EACxB,KAAK,aAAe,IAAI,kBAAoC,CAC1D,iBAAkB,yBAAuB,UACzC,aAAc,eAAa,UAC3B,cAAe,KAAK,iBAAiB,YAAY,EACnD,CAAC,EACD,KAAK,WAAa,IAAI,yBACpB,CACE,gBAAiB,kCACjB,aAAc,eAAa,UAC3B,cAAe,KAAK,iBAAiB,YAAY,GACjD,WAAaM,GACX,KAAK,SAASA,EAAS,CACrB,UAAW,GACX,sBAAuB,EACzB,CAAC,EACH,cAAgBC,GAAa,CAC3B,MAAMC,EAAQ,KAAK,aAAa,SAAS,EACzC,KAAK,sBAAsBD,EAASC,CAAK,CAAC,CAC5C,CACF,EACAL,EAAoB,0BAA0B,CAChD,EACA,KAAK,kBAAoB,IAA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Y,OAAAC,CAAO,EAAIF,EAAa,SAAS,CACnD,SAAU,MAAOH,GAAqB,KAAK,SAASA,CAAI,EACxD,YAAa,MACXD,GACG,KAAK,YAAYA,CAAO,EAC7B,sBAAuB,IAAM,KAAK,aAAa,SAAS,EACxD,gCAAiC,IAAM,KAAK,MAC5C,sBAAwBJ,IACtB,KAAK,sBAAsBA,CAAK,EACzB,KAAK,aAAa,SAAS,GAEpC,iBAAmBW,GACjB,KAAK,kBAAkB,iBAAiBA,CAAS,EACnD,qBAAsB,IAAM,KAAK,mBACjC,wBAAyB,IAAM,KAAK,qBACtC,CAAC,EAED,MAAO,CACL,WAAAF,EACA,OAAAC,CACF,CACF,CAEO,OAAQ,CACb,KAAK,mBAAmB,eAAa,aAAa,EAClD,KAAK,aAAa,SAAS,EAC3B,KAAK,WAAW,KAAK,CACvB,CAEO,iBAAiBjB,EAAwB,CAC9C,OAAO,KAAK,kBAAkB,iBAAiBA,CAAE,CACnD,CAEQ,mBAAmBmB,EAA4B,CACrD,MAAMC,EAAe,KAAK,aAAa,SAAS,EAChD,KAAK,WAAW,gBAAgBD,CAAY,EAC5C,KAAK,aAAa,KAAK,CACrB,GAAGC,EACH,aAAAD,CACF,CAAC,CACH,CAEA,MAAc,gBAAiB,CAC7B,IAAIE,EAEJ,MAAM,IAAI,QAAeC,GAAY,CACnCD,EAAiB,KAAK,aAAa,UAAWd,GAAU,CAClDA,EAAM,eAAiB,eAAa,YACtCc,GAAgB,YAAY,EAC5BC,EAAQ,EAEZ,CAAC,CACH,CAAC,CACH,CACF",
4
+ "sourcesContent": ["import { type Either, Left } from \"purify-ts\";\nimport { BehaviorSubject, type Subscription } 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 { DeviceBusyError, type DmkError } from \"@api/Error\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { type TransportConnectedDevice } from \"@api/transport/model/TransportConnectedDevice\";\nimport { DEVICE_SESSION_REFRESH_INTERVAL } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\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 { DeviceSessionRefresher } from \"./DeviceSessionRefresher\";\n\nexport type SessionConstructorArgs = {\n connectedDevice: TransportConnectedDevice;\n id?: DeviceSessionId;\n};\n\ntype SendApduOptions = {\n isPolling?: boolean;\n triggersDisconnection?: boolean;\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 _refresher: DeviceSessionRefresher;\n private readonly _refresherService: RefresherService;\n private readonly _managerApiService: ManagerApiService;\n private readonly _secureChannelService: SecureChannelService;\n\n constructor(\n { connectedDevice, id = uuidv4() }: SessionConstructorArgs,\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n managerApiService: ManagerApiService,\n secureChannelService: SecureChannelService,\n ) {\n this._id = id;\n this._connectedDevice = connectedDevice;\n this._deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\n });\n this._refresher = new DeviceSessionRefresher(\n {\n refreshInterval: DEVICE_SESSION_REFRESH_INTERVAL,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\n sendApduFn: (rawApdu: Uint8Array) =>\n this.sendApdu(rawApdu, {\n isPolling: true,\n triggersDisconnection: false,\n }),\n updateStateFn: (callback) => {\n const state = this._deviceState.getValue();\n this.setDeviceSessionState(callback(state));\n },\n },\n loggerModuleFactory(\"device-session-refresher\"),\n );\n this._refresherService = new RefresherService(this._refresher);\n this._managerApiService = managerApiService;\n this._secureChannelService = secureChannelService;\n }\n\n public get id() {\n return this._id;\n }\n\n public get connectedDevice() {\n return this._connectedDevice;\n }\n\n public get state() {\n return this._deviceState.asObservable();\n }\n\n public setDeviceSessionState(state: DeviceSessionState) {\n this._deviceState.next(state);\n }\n\n public async sendApdu(\n rawApdu: Uint8Array,\n options: SendApduOptions = {\n isPolling: false,\n triggersDisconnection: false,\n },\n ): Promise<Either<DmkError, ApduResponse>> {\n let reenableRefresher: () => void;\n if (!options.isPolling) {\n reenableRefresher = this._refresherService.disableRefresher(\"sendApdu\");\n await this.waitUntilReady();\n }\n\n const sessionState = this._deviceState.getValue();\n if (sessionState.deviceStatus === DeviceStatus.BUSY) {\n return Left(new DeviceBusyError());\n }\n\n this.updateDeviceStatus(DeviceStatus.BUSY);\n\n const errorOrResponse = await this._connectedDevice.sendApdu(\n rawApdu,\n options.triggersDisconnection,\n );\n\n return errorOrResponse\n .ifRight((response: ApduResponse) => {\n if (CommandUtils.isLockedDeviceResponse(response)) {\n this.updateDeviceStatus(DeviceStatus.LOCKED);\n } else {\n this.updateDeviceStatus(DeviceStatus.CONNECTED);\n }\n\n if (!options.isPolling && reenableRefresher) {\n reenableRefresher();\n }\n })\n .ifLeft(() => {\n this.updateDeviceStatus(DeviceStatus.CONNECTED);\n\n if (!options.isPolling && reenableRefresher) {\n reenableRefresher();\n }\n });\n }\n\n public async sendCommand<Response, Args, ErrorStatusCodes>(\n command: Command<Response, Args, ErrorStatusCodes>,\n ): Promise<CommandResult<Response, ErrorStatusCodes>> {\n const apdu = command.getApdu();\n const response = await this.sendApdu(apdu.getRawApdu(), {\n isPolling: false,\n triggersDisconnection: command.triggersDisconnection ?? false,\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 Error extends DmkError,\n IntermediateValue extends DeviceActionIntermediateValue,\n >(\n deviceAction: DeviceAction<Output, Input, Error, IntermediateValue>,\n ): ExecuteDeviceActionReturnType<Output, Error, 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 ) => this.sendCommand(command),\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\n return {\n observable,\n cancel,\n };\n }\n\n public close() {\n this.updateDeviceStatus(DeviceStatus.NOT_CONNECTED);\n this._deviceState.complete();\n this._refresher.stop();\n }\n\n public disableRefresher(id: string): () => void {\n return this._refresherService.disableRefresher(id);\n }\n\n private updateDeviceStatus(deviceStatus: DeviceStatus) {\n const sessionState = this._deviceState.getValue();\n this._refresher.setDeviceStatus(deviceStatus);\n this._deviceState.next({\n ...sessionState,\n deviceStatus,\n });\n }\n\n private async waitUntilReady() {\n let deviceStateSub: Subscription;\n\n await new Promise<void>((resolve) => {\n deviceStateSub = this._deviceState.subscribe((state) => {\n if (\n [DeviceStatus.LOCKED, DeviceStatus.CONNECTED].includes(\n state.deviceStatus,\n )\n ) {\n deviceStateSub?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,CAAS,EACnD,qBAAsB,IAAM,KAAK,mBACjC,wBAAyB,IAAM,KAAK,qBACtC,CAAC,EAED,MAAO,CACL,WAAAF,EACA,OAAAC,CACF,CACF,CAEO,OAAQ,CACb,KAAK,mBAAmB,eAAa,aAAa,EAClD,KAAK,aAAa,SAAS,EAC3B,KAAK,WAAW,KAAK,CACvB,CAEO,iBAAiBjB,EAAwB,CAC9C,OAAO,KAAK,kBAAkB,iBAAiBA,CAAE,CACnD,CAEQ,mBAAmBmB,EAA4B,CACrD,MAAMC,EAAe,KAAK,aAAa,SAAS,EAChD,KAAK,WAAW,gBAAgBD,CAAY,EAC5C,KAAK,aAAa,KAAK,CACrB,GAAGC,EACH,aAAAD,CACF,CAAC,CACH,CAEA,MAAc,gBAAiB,CAC7B,IAAIE,EAEJ,MAAM,IAAI,QAAeC,GAAY,CACnCD,EAAiB,KAAK,aAAa,UAAWd,GAAU,CAEpD,CAAC,eAAa,OAAQ,eAAa,SAAS,EAAE,SAC5CA,EAAM,YACR,IAEAc,GAAgB,YAAY,EAC5BC,EAAQ,EAEZ,CAAC,CACH,CAAC,CACH,CACF",
6
6
  "names": ["DeviceSession_exports", "__export", "DeviceSession", "__toCommonJS", "import_purify_ts", "import_rxjs", "import_uuid", "import_CommandUtils", "import_DeviceStatus", "import_DeviceSessionState", "import_Error", "import_DeviceSessionRefresherConst", "import_RefresherService", "import_DeviceSessionRefresher", "connectedDevice", "id", "uuidv4", "loggerModuleFactory", "managerApiService", "secureChannelService", "rawApdu", "callback", "state", "options", "reenableRefresher", "response", "command", "apdu", "err", "r", "deviceAction", "observable", "cancel", "blockerId", "deviceStatus", "sessionState", "deviceStateSub", "resolve"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var T=Object.create;var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var d=(t,r)=>{for(var e in r)a(t,e,{get:r[e],enumerable:!0})},h=(t,r,e,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let p of w(r))!B.call(t,p)&&p!==e&&a(t,p,{get:()=>r[p],enumerable:!(i=u(r,p))||i.enumerable});return t};var E=(t,r,e)=>(e=t!=null?T(F(t)):{},h(r||!t||!t.__esModule?a(e,"default",{value:t,enumerable:!0}):e,t)),U=t=>h(a({},"__esModule",{value:!0}),t),f=(t,r,e,i)=>{for(var p=i>1?void 0:i?u(r,e):r,y=t.length-1,g;y>=0;y--)(g=t[y])&&(p=(i?g(r,e,p):g(p))||p);return i&&p&&a(r,e,p),p},v=(t,r)=>(e,i)=>r(e,i,t);var b={};d(b,{AxiosManagerApiDataSource:()=>m});module.exports=U(b);var s=E(require("axios")),A=require("inversify"),l=require("purify-ts"),D=require("../../manager-api/di/managerApiTypes"),o=require("../../manager-api/model/Application"),c=require("../../manager-api/model/Errors"),n=require("./ManagerApiDto");let m=class{managerApiBaseUrl;webSocketBaseUrl;constructor({managerApiUrl:r,webSocketUrl:e}){this.managerApiBaseUrl=r,this.webSocketBaseUrl=e,console.log(this.webSocketBaseUrl)}getDeviceVersion(r,e){return(0,l.EitherAsync)(()=>s.default.get(`${this.managerApiBaseUrl}/get_device_version`,{params:{target_id:r,provider:e}})).map(i=>i.data).mapLeft(i=>new c.HttpFetchApiError(i))}getFirmwareVersion(r,e,i){return(0,l.EitherAsync)(()=>s.default.get(`${this.managerApiBaseUrl}/get_firmware_version`,{params:{device_version:e,version_name:r,provider:i}})).map(p=>p.data).mapLeft(p=>new c.HttpFetchApiError(p))}getAppsByHash(r){return(0,l.EitherAsync)(()=>s.default.post(`${this.managerApiBaseUrl}/v2/apps/hash`,r)).map(e=>e.data).map(e=>this.mapApplicationDtoToApplication(e)).mapLeft(e=>new c.HttpFetchApiError(e))}mapAppTypeDtoToAppType(r){switch(r){case n.AppTypeDto.currency:return o.AppType.currency;case n.AppTypeDto.plugin:return o.AppType.plugin;case n.AppTypeDto.tool:return o.AppType.tool;case n.AppTypeDto.swap:return o.AppType.swap}}mapApplicationDtoToApplication(r){return r.map(e=>{if(e===null)return null;const{applicationType:i,...p}=e;return{...p,applicationType:this.mapAppTypeDtoToAppType(i)}})}};m=f([(0,A.injectable)(),v(0,(0,A.inject)(D.managerApiTypes.DmkConfig))],m);0&&(module.exports={AxiosManagerApiDataSource});
1
+ "use strict";var d=Object.create;var o=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var E=(i,r)=>{for(var e in r)o(i,e,{get:r[e],enumerable:!0})},f=(i,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let p of w(r))!F.call(i,p)&&p!==e&&o(i,p,{get:()=>r[p],enumerable:!(t=h(r,p))||t.enumerable});return i};var V=(i,r,e)=>(e=i!=null?d(T(i)):{},f(r||!i||!i.__esModule?o(e,"default",{value:i,enumerable:!0}):e,i)),_=i=>f(o({},"__esModule",{value:!0}),i),v=(i,r,e,t)=>{for(var p=t>1?void 0:t?h(r,e):r,a=i.length-1,g;a>=0;a--)(g=i[a])&&(p=(t?g(r,e,p):g(p))||p);return t&&p&&o(r,e,p),p},u=(i,r)=>(e,t)=>r(e,t,i);var B={};E(B,{AxiosManagerApiDataSource:()=>A});module.exports=_(B);var n=V(require("axios")),y=require("inversify"),s=require("purify-ts"),D=require("../../manager-api/di/managerApiTypes"),m=require("../../manager-api/model/Application"),c=require("../../manager-api/model/Errors"),l=require("./ManagerApiDto");let A=class{managerApiBaseUrl;constructor({managerApiUrl:r}){this.managerApiBaseUrl=r}getAppList(r){const{targetId:e,provider:t,firmwareVersionName:p}=r;return(0,s.EitherAsync)(()=>n.default.get(`${this.managerApiBaseUrl}/v2/apps/by-target`,{params:{target_id:e,provider:t,firmware_version_name:p}})).map(a=>a.data).mapLeft(a=>new c.HttpFetchApiError(a))}getDeviceVersion(r){const{targetId:e,provider:t}=r;return(0,s.EitherAsync)(()=>n.default.get(`${this.managerApiBaseUrl}/get_device_version`,{params:{target_id:e,provider:t}})).map(p=>p.data).mapLeft(p=>new c.HttpFetchApiError(p))}getFirmwareVersion(r){const{deviceId:e,version:t,provider:p}=r;return(0,s.EitherAsync)(()=>n.default.get(`${this.managerApiBaseUrl}/get_firmware_version`,{params:{device_version:e,version_name:t,provider:p}})).map(a=>a.data).mapLeft(a=>new c.HttpFetchApiError(a))}getAppsByHash(r){const{hashes:e}=r;return(0,s.EitherAsync)(()=>n.default.post(`${this.managerApiBaseUrl}/v2/apps/hash`,e)).map(t=>t.data).map(t=>this.mapApplicationDtoToApplication(t)).mapLeft(t=>new c.HttpFetchApiError(t))}mapAppTypeDtoToAppType(r){switch(r){case l.AppTypeDto.currency:return m.AppType.currency;case l.AppTypeDto.plugin:return m.AppType.plugin;case l.AppTypeDto.tool:return m.AppType.tool;case l.AppTypeDto.swap:return m.AppType.swap}}mapApplicationDtoToApplication(r){return r.map(e=>{if(e===null)return null;const{applicationType:t,...p}=e;return{...p,applicationType:this.mapAppTypeDtoToAppType(t)}})}};A=v([(0,y.injectable)(),u(0,(0,y.inject)(D.managerApiTypes.DmkConfig))],A);0&&(module.exports={AxiosManagerApiDataSource});
2
2
  //# sourceMappingURL=AxiosManagerApiDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/manager-api/data/AxiosManagerApiDataSource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { EitherAsync } from \"purify-ts\";\n\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport {\n type Application,\n AppType,\n} from \"@internal/manager-api/model/Application\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\n\nimport { ManagerApiDataSource } from \"./ManagerApiDataSource\";\nimport { ApplicationDto, AppTypeDto } from \"./ManagerApiDto\";\n\n@injectable()\nexport class AxiosManagerApiDataSource implements ManagerApiDataSource {\n private readonly managerApiBaseUrl: string;\n private readonly webSocketBaseUrl: string;\n\n constructor(\n @inject(managerApiTypes.DmkConfig)\n { managerApiUrl, webSocketUrl }: DmkConfig,\n ) {\n this.managerApiBaseUrl = managerApiUrl;\n this.webSocketBaseUrl = webSocketUrl;\n console.log(this.webSocketBaseUrl);\n }\n\n getDeviceVersion(\n targetId: string,\n provider: number,\n ): EitherAsync<HttpFetchApiError, DeviceVersion> {\n return EitherAsync(() =>\n axios.get<DeviceVersion>(`${this.managerApiBaseUrl}/get_device_version`, {\n params: {\n target_id: targetId,\n provider,\n },\n }),\n )\n .map((res) => res.data)\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n getFirmwareVersion(\n version: string,\n deviceId: number,\n provider: number,\n ): EitherAsync<HttpFetchApiError, FinalFirmware> {\n return EitherAsync(() =>\n axios.get<FinalFirmware>(\n `${this.managerApiBaseUrl}/get_firmware_version`,\n {\n params: {\n device_version: deviceId,\n version_name: version,\n provider,\n },\n },\n ),\n )\n .map((res) => res.data)\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n getAppsByHash(\n hashes: string[],\n ): EitherAsync<HttpFetchApiError, Array<Application | null>> {\n return EitherAsync(() =>\n axios.post<Array<ApplicationDto | null>>(\n `${this.managerApiBaseUrl}/v2/apps/hash`,\n hashes,\n ),\n )\n .map((res) => res.data)\n .map((apps) => this.mapApplicationDtoToApplication(apps))\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n private mapAppTypeDtoToAppType(appType: AppTypeDto): AppType {\n switch (appType) {\n case AppTypeDto.currency:\n return AppType.currency;\n case AppTypeDto.plugin:\n return AppType.plugin;\n case AppTypeDto.tool:\n return AppType.tool;\n case AppTypeDto.swap:\n return AppType.swap;\n }\n }\n\n private mapApplicationDtoToApplication(\n apps: Array<ApplicationDto | null>,\n ): Array<Application | null> {\n return apps.map((app) => {\n if (app === null) {\n return null;\n }\n\n const { applicationType, ...rest } = app;\n\n return {\n ...rest,\n applicationType: this.mapAppTypeDtoToAppType(applicationType),\n };\n });\n }\n}\n"],
5
- "mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAA4B,qBAG5BC,EAAgC,oDAChCC,EAGO,mDAEPC,EAAkC,8CAIlCC,EAA2C,2BAGpC,IAAMC,EAAN,KAAgE,CACpD,kBACA,iBAEjB,YAEE,CAAE,cAAAC,EAAe,aAAAC,CAAa,EAC9B,CACA,KAAK,kBAAoBD,EACzB,KAAK,iBAAmBC,EACxB,QAAQ,IAAI,KAAK,gBAAgB,CACnC,CAEA,iBACEC,EACAC,EAC+C,CAC/C,SAAO,eAAY,IACjB,EAAAC,QAAM,IAAmB,GAAG,KAAK,iBAAiB,sBAAuB,CACvE,OAAQ,CACN,UAAWF,EACX,SAAAC,CACF,CACF,CAAC,CACH,EACG,IAAKE,GAAQA,EAAI,IAAI,EACrB,QAASC,GAAU,IAAI,oBAAkBA,CAAK,CAAC,CACpD,CAEA,mBACEC,EACAC,EACAL,EAC+C,CAC/C,SAAO,eAAY,IACjB,EAAAC,QAAM,IACJ,GAAG,KAAK,iBAAiB,wBACzB,CACE,OAAQ,CACN,eAAgBI,EAChB,aAAcD,EACd,SAAAJ,CACF,CACF,CACF,CACF,EACG,IAAKE,GAAQA,EAAI,IAAI,EACrB,QAASC,GAAU,IAAI,oBAAkBA,CAAK,CAAC,CACpD,CAEA,cACEG,EAC2D,CAC3D,SAAO,eAAY,IACjB,EAAAL,QAAM,KACJ,GAAG,KAAK,iBAAiB,gBACzBK,CACF,CACF,EACG,IAAKJ,GAAQA,EAAI,IAAI,EACrB,IAAKK,GAAS,KAAK,+BAA+BA,CAAI,CAAC,EACvD,QAASJ,GAAU,IAAI,oBAAkBA,CAAK,CAAC,CACpD,CAEQ,uBAAuBK,EAA8B,CAC3D,OAAQA,EAAS,CACf,KAAK,aAAW,SACd,OAAO,UAAQ,SACjB,KAAK,aAAW,OACd,OAAO,UAAQ,OACjB,KAAK,aAAW,KACd,OAAO,UAAQ,KACjB,KAAK,aAAW,KACd,OAAO,UAAQ,IACnB,CACF,CAEQ,+BACND,EAC2B,CAC3B,OAAOA,EAAK,IAAKE,GAAQ,CACvB,GAAIA,IAAQ,KACV,OAAO,KAGT,KAAM,CAAE,gBAAAC,EAAiB,GAAGC,CAAK,EAAIF,EAErC,MAAO,CACL,GAAGE,EACH,gBAAiB,KAAK,uBAAuBD,CAAe,CAC9D,CACF,CAAC,CACH,CACF,EA7Fad,EAANgB,EAAA,IADN,cAAW,EAMPC,EAAA,eAAO,kBAAgB,SAAS,IALxBjB",
6
- "names": ["AxiosManagerApiDataSource_exports", "__export", "AxiosManagerApiDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_managerApiTypes", "import_Application", "import_Errors", "import_ManagerApiDto", "AxiosManagerApiDataSource", "managerApiUrl", "webSocketUrl", "targetId", "provider", "axios", "res", "error", "version", "deviceId", "hashes", "apps", "appType", "app", "applicationType", "rest", "__decorateClass", "__decorateParam"]
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { EitherAsync } from \"purify-ts\";\n\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport {\n type Application,\n AppType,\n} from \"@internal/manager-api/model/Application\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\nimport {\n type GetAppByHashParams,\n type GetAppListParams,\n type GetDeviceVersionParams,\n type GetFirmwareVersionParams,\n} from \"@internal/manager-api/model/Params\";\n\nimport { ManagerApiDataSource } from \"./ManagerApiDataSource\";\nimport { ApplicationDto, AppTypeDto } from \"./ManagerApiDto\";\n\n@injectable()\nexport class AxiosManagerApiDataSource implements ManagerApiDataSource {\n private readonly managerApiBaseUrl: string;\n\n constructor(\n @inject(managerApiTypes.DmkConfig)\n { managerApiUrl }: DmkConfig,\n ) {\n this.managerApiBaseUrl = managerApiUrl;\n }\n\n getAppList(\n params: GetAppListParams,\n ): EitherAsync<HttpFetchApiError, Application[]> {\n const { targetId, provider, firmwareVersionName } = params;\n return EitherAsync(() =>\n axios.get<Application[]>(`${this.managerApiBaseUrl}/v2/apps/by-target`, {\n params: {\n target_id: targetId,\n provider,\n firmware_version_name: firmwareVersionName,\n },\n }),\n )\n .map((res) => res.data)\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n getDeviceVersion(\n params: GetDeviceVersionParams,\n ): EitherAsync<HttpFetchApiError, DeviceVersion> {\n const { targetId, provider } = params;\n return EitherAsync(() =>\n axios.get<DeviceVersion>(`${this.managerApiBaseUrl}/get_device_version`, {\n params: {\n target_id: targetId,\n provider,\n },\n }),\n )\n .map((res) => res.data)\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n getFirmwareVersion(\n params: GetFirmwareVersionParams,\n ): EitherAsync<HttpFetchApiError, FinalFirmware> {\n const { deviceId, version, provider } = params;\n return EitherAsync(() =>\n axios.get<FinalFirmware>(\n `${this.managerApiBaseUrl}/get_firmware_version`,\n {\n params: {\n device_version: deviceId,\n version_name: version,\n provider,\n },\n },\n ),\n )\n .map((res) => res.data)\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n getAppsByHash(\n params: GetAppByHashParams,\n ): EitherAsync<HttpFetchApiError, Array<Application | null>> {\n const { hashes } = params;\n return EitherAsync(() =>\n axios.post<Array<ApplicationDto | null>>(\n `${this.managerApiBaseUrl}/v2/apps/hash`,\n hashes,\n ),\n )\n .map((res) => res.data)\n .map((apps) => this.mapApplicationDtoToApplication(apps))\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n private mapAppTypeDtoToAppType(appType: AppTypeDto): AppType {\n switch (appType) {\n case AppTypeDto.currency:\n return AppType.currency;\n case AppTypeDto.plugin:\n return AppType.plugin;\n case AppTypeDto.tool:\n return AppType.tool;\n case AppTypeDto.swap:\n return AppType.swap;\n }\n }\n\n private mapApplicationDtoToApplication(\n apps: Array<ApplicationDto | null>,\n ): Array<Application | null> {\n return apps.map((app) => {\n if (app === null) {\n return null;\n }\n const { applicationType, ...rest } = app;\n return {\n ...rest,\n applicationType: this.mapAppTypeDtoToAppType(applicationType),\n };\n });\n }\n}\n"],
5
+ "mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAA4B,qBAG5BC,EAAgC,oDAChCC,EAGO,mDAEPC,EAAkC,8CAUlCC,EAA2C,2BAGpC,IAAMC,EAAN,KAAgE,CACpD,kBAEjB,YAEE,CAAE,cAAAC,CAAc,EAChB,CACA,KAAK,kBAAoBA,CAC3B,CAEA,WACEC,EAC+C,CAC/C,KAAM,CAAE,SAAAC,EAAU,SAAAC,EAAU,oBAAAC,CAAoB,EAAIH,EACpD,SAAO,eAAY,IACjB,EAAAI,QAAM,IAAmB,GAAG,KAAK,iBAAiB,qBAAsB,CACtE,OAAQ,CACN,UAAWH,EACX,SAAAC,EACA,sBAAuBC,CACzB,CACF,CAAC,CACH,EACG,IAAKE,GAAQA,EAAI,IAAI,EACrB,QAASC,GAAU,IAAI,oBAAkBA,CAAK,CAAC,CACpD,CAEA,iBACEN,EAC+C,CAC/C,KAAM,CAAE,SAAAC,EAAU,SAAAC,CAAS,EAAIF,EAC/B,SAAO,eAAY,IACjB,EAAAI,QAAM,IAAmB,GAAG,KAAK,iBAAiB,sBAAuB,CACvE,OAAQ,CACN,UAAWH,EACX,SAAAC,CACF,CACF,CAAC,CACH,EACG,IAAKG,GAAQA,EAAI,IAAI,EACrB,QAASC,GAAU,IAAI,oBAAkBA,CAAK,CAAC,CACpD,CAEA,mBACEN,EAC+C,CAC/C,KAAM,CAAE,SAAAO,EAAU,QAAAC,EAAS,SAAAN,CAAS,EAAIF,EACxC,SAAO,eAAY,IACjB,EAAAI,QAAM,IACJ,GAAG,KAAK,iBAAiB,wBACzB,CACE,OAAQ,CACN,eAAgBG,EAChB,aAAcC,EACd,SAAAN,CACF,CACF,CACF,CACF,EACG,IAAKG,GAAQA,EAAI,IAAI,EACrB,QAASC,GAAU,IAAI,oBAAkBA,CAAK,CAAC,CACpD,CAEA,cACEN,EAC2D,CAC3D,KAAM,CAAE,OAAAS,CAAO,EAAIT,EACnB,SAAO,eAAY,IACjB,EAAAI,QAAM,KACJ,GAAG,KAAK,iBAAiB,gBACzBK,CACF,CACF,EACG,IAAKJ,GAAQA,EAAI,IAAI,EACrB,IAAKK,GAAS,KAAK,+BAA+BA,CAAI,CAAC,EACvD,QAASJ,GAAU,IAAI,oBAAkBA,CAAK,CAAC,CACpD,CAEQ,uBAAuBK,EAA8B,CAC3D,OAAQA,EAAS,CACf,KAAK,aAAW,SACd,OAAO,UAAQ,SACjB,KAAK,aAAW,OACd,OAAO,UAAQ,OACjB,KAAK,aAAW,KACd,OAAO,UAAQ,KACjB,KAAK,aAAW,KACd,OAAO,UAAQ,IACnB,CACF,CAEQ,+BACND,EAC2B,CAC3B,OAAOA,EAAK,IAAKE,GAAQ,CACvB,GAAIA,IAAQ,KACV,OAAO,KAET,KAAM,CAAE,gBAAAC,EAAiB,GAAGC,CAAK,EAAIF,EACrC,MAAO,CACL,GAAGE,EACH,gBAAiB,KAAK,uBAAuBD,CAAe,CAC9D,CACF,CAAC,CACH,CACF,EAzGaf,EAANiB,EAAA,IADN,cAAW,EAKPC,EAAA,eAAO,kBAAgB,SAAS,IAJxBlB",
6
+ "names": ["AxiosManagerApiDataSource_exports", "__export", "AxiosManagerApiDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_managerApiTypes", "import_Application", "import_Errors", "import_ManagerApiDto", "AxiosManagerApiDataSource", "managerApiUrl", "params", "targetId", "provider", "firmwareVersionName", "axios", "res", "error", "deviceId", "version", "hashes", "apps", "appType", "app", "applicationType", "rest", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var m=Object.create;var l=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var A=(r,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of v(e))!f.call(r,i)&&i!==s&&l(r,i,{get:()=>e[i],enumerable:!(n=d(e,i))||n.enumerable});return r};var E=(r,e,s)=>(s=r!=null?m(g(r)):{},A(e||!r||!r.__esModule?l(s,"default",{value:r,enumerable:!0}):s,r));var o=E(require("axios")),a=require("purify-ts"),t=require("../../../api/device-action/__test-utils__/data"),p=require("../../manager-api/model/Errors"),c=require("./AxiosManagerApiDataSource");vi.mock("axios");const h={id:17,target_id:"857735172"},u={id:361,perso:"perso_11"};describe("AxiosManagerApiDataSource",()=>{describe("getAppsByHash",()=>{describe("success cases",()=>{let r;beforeEach(()=>{r=new c.AxiosManagerApiDataSource({})}),afterEach(()=>{vi.clearAllMocks()}),it("with BTC app, should return the metadata",async()=>{vi.spyOn(o.default,"post").mockResolvedValue({data:[t.BTC_APP_METADATA]});const e=[t.BTC_APP.appFullHash],s=await r.getAppsByHash(e);expect(s).toEqual((0,a.Right)([t.BTC_APP_METADATA]))}),it("with no apps, should return an empty list",async()=>{vi.spyOn(o.default,"post").mockResolvedValue({data:[]});const e=[],s=await r.getAppsByHash(e);expect(s).toEqual((0,a.Right)([]))}),it("with BTC app and custom lock screen, should return the metadata",async()=>{vi.spyOn(o.default,"post").mockResolvedValue({data:[t.BTC_APP_METADATA,t.CUSTOM_LOCK_SCREEN_APP_METADATA]});const e=[t.BTC_APP.appFullHash,t.CUSTOM_LOCK_SCREEN_APP.appFullHash],s=await r.getAppsByHash(e);expect(s).toEqual((0,a.Right)([t.BTC_APP_METADATA,t.CUSTOM_LOCK_SCREEN_APP_METADATA]))})}),describe("error cases",()=>{afterEach(()=>{vi.clearAllMocks()}),it("should throw an error if the request fails",()=>{const r=new c.AxiosManagerApiDataSource({}),e=new Error("fetch error");vi.spyOn(o.default,"post").mockRejectedValue(e);const s=[t.BTC_APP.appFullHash],n=r.getAppsByHash(s);expect(n).resolves.toEqual((0,a.Left)(new p.HttpFetchApiError(e)))})})}),describe("getDeviceVersion",()=>{let r;beforeEach(()=>{r=new c.AxiosManagerApiDataSource({})}),afterEach(()=>{vi.clearAllMocks()}),it("should return a complete device version",()=>{vi.spyOn(o.default,"get").mockResolvedValue({data:h});const e=r.getDeviceVersion("targetId",42);expect(e).resolves.toEqual((0,a.Right)(h))}),it("should return an error if the request fails",()=>{const e=new Error("fetch error");vi.spyOn(o.default,"get").mockRejectedValue(e);const s=r.getDeviceVersion("targetId",42);expect(s).resolves.toEqual((0,a.Left)(new p.HttpFetchApiError(e)))})}),describe("getFirmwareVersion",()=>{let r;beforeEach(()=>{r=new c.AxiosManagerApiDataSource({})}),afterEach(()=>{vi.clearAllMocks()}),it("should return a complete firmware version",()=>{vi.spyOn(o.default,"get").mockResolvedValue({data:u});const e=r.getFirmwareVersion("versionName",42,21);expect(e).resolves.toEqual((0,a.Right)(u))}),it("should return an error if the request fails",()=>{const e=new Error("fetch error");vi.spyOn(o.default,"get").mockRejectedValue(e);const s=r.getFirmwareVersion("versionName",42,21);expect(s).resolves.toEqual((0,a.Left)(new p.HttpFetchApiError(e)))})})});
1
+ "use strict";var m=Object.create;var l=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var A=(r,e,t,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of v(e))!f.call(r,c)&&c!==t&&l(r,c,{get:()=>e[c],enumerable:!(p=h(e,c))||p.enumerable});return r};var E=(r,e,t)=>(t=r!=null?m(g(r)):{},A(e||!r||!r.__esModule?l(t,"default",{value:r,enumerable:!0}):t,r));var o=E(require("axios")),a=require("purify-ts"),s=require("../../../api/device-action/__test-utils__/data"),n=require("../../manager-api/model/Errors"),i=require("./AxiosManagerApiDataSource");vi.mock("axios");const d={id:17,target_id:"857735172"},u={id:361,perso:"perso_11"};describe("AxiosManagerApiDataSource",()=>{describe("getAppList",()=>{let r;beforeEach(()=>{r=new i.AxiosManagerApiDataSource({})}),afterEach(()=>{vi.clearAllMocks()}),it("should return a list of applications",()=>{const e=[s.BTC_APP_METADATA,s.CUSTOM_LOCK_SCREEN_APP_METADATA];vi.spyOn(o.default,"get").mockResolvedValue({data:e});const t=r.getAppList({targetId:"targetId",provider:42,firmwareVersionName:"firmwareVersionName"});expect(t).resolves.toEqual((0,a.Right)(e))}),it("should return an error if the request fails",()=>{const e=new Error("fetch error");vi.spyOn(o.default,"get").mockRejectedValue(e);const t=r.getAppList({targetId:"targetId",provider:42,firmwareVersionName:"firmwareVersionName"});expect(t).resolves.toEqual((0,a.Left)(new n.HttpFetchApiError(e)))})}),describe("getAppsByHash",()=>{describe("success cases",()=>{let r;beforeEach(()=>{r=new i.AxiosManagerApiDataSource({})}),afterEach(()=>{vi.clearAllMocks()}),it("with BTC app, should return the metadata",async()=>{vi.spyOn(o.default,"post").mockResolvedValue({data:[s.BTC_APP_METADATA]});const e=[s.BTC_APP.appFullHash],t=await r.getAppsByHash({hashes:e});expect(t).toEqual((0,a.Right)([s.BTC_APP_METADATA]))}),it("with no apps, should return an empty list",async()=>{vi.spyOn(o.default,"post").mockResolvedValue({data:[]});const e=[],t=await r.getAppsByHash({hashes:e});expect(t).toEqual((0,a.Right)([]))}),it("with BTC app and custom lock screen, should return the metadata",async()=>{vi.spyOn(o.default,"post").mockResolvedValue({data:[s.BTC_APP_METADATA,s.CUSTOM_LOCK_SCREEN_APP_METADATA]});const e=[s.BTC_APP.appFullHash,s.CUSTOM_LOCK_SCREEN_APP.appFullHash],t=await r.getAppsByHash({hashes:e});expect(t).toEqual((0,a.Right)([s.BTC_APP_METADATA,s.CUSTOM_LOCK_SCREEN_APP_METADATA]))})}),describe("error cases",()=>{afterEach(()=>{vi.clearAllMocks()}),it("should throw an error if the request fails",()=>{const r=new i.AxiosManagerApiDataSource({}),e=new Error("fetch error");vi.spyOn(o.default,"post").mockRejectedValue(e);const t=[s.BTC_APP.appFullHash],p=r.getAppsByHash({hashes:t});expect(p).resolves.toEqual((0,a.Left)(new n.HttpFetchApiError(e)))})})}),describe("getDeviceVersion",()=>{let r;beforeEach(()=>{r=new i.AxiosManagerApiDataSource({})}),afterEach(()=>{vi.clearAllMocks()}),it("should return a complete device version",()=>{vi.spyOn(o.default,"get").mockResolvedValue({data:d});const e=r.getDeviceVersion({targetId:"targetId",provider:42});expect(e).resolves.toEqual((0,a.Right)(d))}),it("should return an error if the request fails",()=>{const e=new Error("fetch error");vi.spyOn(o.default,"get").mockRejectedValue(e);const t=r.getDeviceVersion({targetId:"targetId",provider:42});expect(t).resolves.toEqual((0,a.Left)(new n.HttpFetchApiError(e)))})}),describe("getFirmwareVersion",()=>{let r;beforeEach(()=>{r=new i.AxiosManagerApiDataSource({})}),afterEach(()=>{vi.clearAllMocks()}),it("should return a complete firmware version",()=>{vi.spyOn(o.default,"get").mockResolvedValue({data:u});const e=r.getFirmwareVersion({version:"versionName",deviceId:42,provider:21});expect(e).resolves.toEqual((0,a.Right)(u))}),it("should return an error if the request fails",()=>{const e=new Error("fetch error");vi.spyOn(o.default,"get").mockRejectedValue(e);const t=r.getFirmwareVersion({version:"versionName",deviceId:42,provider:21});expect(t).resolves.toEqual((0,a.Left)(new n.HttpFetchApiError(e)))})})});
2
2
  //# sourceMappingURL=AxiosManagerApiDataSource.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/manager-api/data/AxiosManagerApiDataSource.test.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport {\n BTC_APP,\n BTC_APP_METADATA,\n CUSTOM_LOCK_SCREEN_APP,\n CUSTOM_LOCK_SCREEN_APP_METADATA,\n} from \"@api/device-action/__test-utils__/data\";\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\n\nimport { AxiosManagerApiDataSource } from \"./AxiosManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"./ManagerApiDataSource\";\n\nvi.mock(\"axios\");\n\nconst mockGetDeviceVersion = {\n id: 17,\n target_id: \"857735172\",\n};\n\nconst mockGetFirmwareVersion = {\n id: 361,\n perso: \"perso_11\",\n};\n\ndescribe(\"AxiosManagerApiDataSource\", () => {\n describe(\"getAppsByHash\", () => {\n describe(\"success cases\", () => {\n let api: ManagerApiDataSource;\n beforeEach(() => {\n api = new AxiosManagerApiDataSource({} as DmkConfig);\n });\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"with BTC app, should return the metadata\", async () => {\n vi.spyOn(axios, \"post\").mockResolvedValue({\n data: [BTC_APP_METADATA],\n });\n\n const hashes = [BTC_APP.appFullHash];\n\n const apps = await api.getAppsByHash(hashes);\n\n expect(apps).toEqual(Right([BTC_APP_METADATA]));\n });\n\n it(\"with no apps, should return an empty list\", async () => {\n vi.spyOn(axios, \"post\").mockResolvedValue({\n data: [],\n });\n\n const hashes: string[] = [];\n\n const apps = await api.getAppsByHash(hashes);\n\n expect(apps).toEqual(Right([]));\n });\n\n it(\"with BTC app and custom lock screen, should return the metadata\", async () => {\n vi.spyOn(axios, \"post\").mockResolvedValue({\n data: [BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA],\n });\n\n const hashes = [\n BTC_APP.appFullHash,\n CUSTOM_LOCK_SCREEN_APP.appFullHash,\n ];\n\n const apps = await api.getAppsByHash(hashes);\n\n expect(apps).toEqual(\n Right([BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA]),\n );\n });\n });\n\n describe(\"error cases\", () => {\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"should throw an error if the request fails\", () => {\n // given\n const api = new AxiosManagerApiDataSource({} as DmkConfig);\n\n const err = new Error(\"fetch error\");\n vi.spyOn(axios, \"post\").mockRejectedValue(err);\n\n const hashes = [BTC_APP.appFullHash];\n\n // when\n const response = api.getAppsByHash(hashes);\n\n // then\n expect(response).resolves.toEqual(Left(new HttpFetchApiError(err)));\n });\n });\n });\n\n describe(\"getDeviceVersion\", () => {\n let api: ManagerApiDataSource;\n beforeEach(() => {\n api = new AxiosManagerApiDataSource({} as DmkConfig);\n });\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"should return a complete device version\", () => {\n // given\n vi.spyOn(axios, \"get\").mockResolvedValue({ data: mockGetDeviceVersion });\n\n // when\n const response = api.getDeviceVersion(\"targetId\", 42);\n\n // then\n expect(response).resolves.toEqual(Right(mockGetDeviceVersion));\n });\n it(\"should return an error if the request fails\", () => {\n // given\n\n const error = new Error(\"fetch error\");\n vi.spyOn(axios, \"get\").mockRejectedValue(error);\n\n // when\n const response = api.getDeviceVersion(\"targetId\", 42);\n\n // then\n expect(response).resolves.toEqual(Left(new HttpFetchApiError(error)));\n });\n });\n\n describe(\"getFirmwareVersion\", () => {\n let api: ManagerApiDataSource;\n beforeEach(() => {\n api = new AxiosManagerApiDataSource({} as DmkConfig);\n });\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"should return a complete firmware version\", () => {\n // given\n vi.spyOn(axios, \"get\").mockResolvedValue({\n data: mockGetFirmwareVersion,\n });\n\n // when\n const response = api.getFirmwareVersion(\"versionName\", 42, 21);\n\n // then\n expect(response).resolves.toEqual(Right(mockGetFirmwareVersion));\n });\n it(\"should return an error if the request fails\", () => {\n // given\n const error = new Error(\"fetch error\");\n vi.spyOn(axios, \"get\").mockRejectedValue(error);\n\n // when\n const response = api.getFirmwareVersion(\"versionName\", 42, 21);\n\n // then\n expect(response).resolves.toEqual(Left(new H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AAC,EACD,UAAU,IAAM,CACd,GAAG,cAAc,CACnB,CAAC,EACD,GAAG,4CAA6C,IAAM,CAEpD,GAAG,MAAM,EAAAC,QAAO,KAAK,EAAE,kBAAkB,CACvC,KAAMF,CACR,CAAC,EAGD,MAAMM,EAAWL,EAAI,mBAAmB,cAAe,GAAI,EAAE,EAG7D,OAAOK,CAAQ,EAAE,SAAS,WAAQ,SAAMN,CAAsB,CAAC,CACjE,CAAC,EACD,GAAG,8CAA+C,IAAM,CAEtD,MAAMO,EAAQ,IAAI,MAAM,aAAa,EACrC,GAAG,MAAM,EAAAL,QAAO,KAAK,EAAE,kBAAkBK,CAAK,EAG9C,MAAMD,EAAWL,EAAI,mBAAmB,cAAe,GAAI,EAAE,EAG7D,OAAOK,CAAQ,EAAE,SAAS,WAAQ,QAAK,IAAI,oBAAkBC,CAAK,CAAC,CAAC,CACtE,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_axios", "import_purify_ts", "import_data", "import_Errors", "import_AxiosManagerApiDataSource", "mockGetDeviceVersion", "mockGetFirmwareVersion", "api", "axios", "hashes", "apps", "err", "response", "error"]
4
+ "sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport {\n BTC_APP,\n BTC_APP_METADATA,\n CUSTOM_LOCK_SCREEN_APP,\n CUSTOM_LOCK_SCREEN_APP_METADATA,\n} from \"@api/device-action/__test-utils__/data\";\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\n\nimport { AxiosManagerApiDataSource } from \"./AxiosManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"./ManagerApiDataSource\";\n\nvi.mock(\"axios\");\n\nconst mockGetDeviceVersion = {\n id: 17,\n target_id: \"857735172\",\n};\n\nconst mockGetFirmwareVersion = {\n id: 361,\n perso: \"perso_11\",\n};\n\ndescribe(\"AxiosManagerApiDataSource\", () => {\n describe(\"getAppList\", () => {\n let api: ManagerApiDataSource;\n beforeEach(() => {\n api = new AxiosManagerApiDataSource({} as DmkConfig);\n });\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"should return a list of applications\", () => {\n // given\n const apps = [BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA];\n vi.spyOn(axios, \"get\").mockResolvedValue({ data: apps });\n\n // when\n const response = api.getAppList({\n targetId: \"targetId\",\n provider: 42,\n firmwareVersionName: \"firmwareVersionName\",\n });\n\n // then\n expect(response).resolves.toEqual(Right(apps));\n });\n it(\"should return an error if the request fails\", () => {\n // given\n const error = new Error(\"fetch error\");\n vi.spyOn(axios, \"get\").mockRejectedValue(error);\n\n // when\n const response = api.getAppList({\n targetId: \"targetId\",\n provider: 42,\n firmwareVersionName: \"firmwareVersionName\",\n });\n\n // then\n expect(response).resolves.toEqual(Left(new HttpFetchApiError(error)));\n });\n });\n describe(\"getAppsByHash\", () => {\n describe(\"success cases\", () => {\n let api: ManagerApiDataSource;\n beforeEach(() => {\n api = new AxiosManagerApiDataSource({} as DmkConfig);\n });\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"with BTC app, should return the metadata\", async () => {\n vi.spyOn(axios, \"post\").mockResolvedValue({\n data: [BTC_APP_METADATA],\n });\n\n const hashes = [BTC_APP.appFullHash];\n\n const apps = await api.getAppsByHash({ hashes });\n\n expect(apps).toEqual(Right([BTC_APP_METADATA]));\n });\n\n it(\"with no apps, should return an empty list\", async () => {\n vi.spyOn(axios, \"post\").mockResolvedValue({\n data: [],\n });\n\n const hashes: string[] = [];\n\n const apps = await api.getAppsByHash({ hashes });\n\n expect(apps).toEqual(Right([]));\n });\n\n it(\"with BTC app and custom lock screen, should return the metadata\", async () => {\n vi.spyOn(axios, \"post\").mockResolvedValue({\n data: [BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA],\n });\n\n const hashes = [\n BTC_APP.appFullHash,\n CUSTOM_LOCK_SCREEN_APP.appFullHash,\n ];\n\n const apps = await api.getAppsByHash({ hashes });\n\n expect(apps).toEqual(\n Right([BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA]),\n );\n });\n });\n\n describe(\"error cases\", () => {\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"should throw an error if the request fails\", () => {\n // given\n const api = new AxiosManagerApiDataSource({} as DmkConfig);\n\n const err = new Error(\"fetch error\");\n vi.spyOn(axios, \"post\").mockRejectedValue(err);\n\n const hashes = [BTC_APP.appFullHash];\n\n // when\n const response = api.getAppsByHash({ hashes });\n\n // then\n expect(response).resolves.toEqual(Left(new HttpFetchApiError(err)));\n });\n });\n });\n\n describe(\"getDeviceVersion\", () => {\n let api: ManagerApiDataSource;\n beforeEach(() => {\n api = new AxiosManagerApiDataSource({} as DmkConfig);\n });\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"should return a complete device version\", () => {\n // given\n vi.spyOn(axios, \"get\").mockResolvedValue({ data: mockGetDeviceVersion });\n\n // when\n const response = api.getDeviceVersion({\n targetId: \"targetId\",\n provider: 42,\n });\n\n // then\n expect(response).resolves.toEqual(Right(mockGetDeviceVersion));\n });\n it(\"should return an error if the request fails\", () => {\n // given\n\n const error = new Error(\"fetch error\");\n vi.spyOn(axios, \"get\").mockRejectedValue(error);\n\n // when\n const response = api.getDeviceVersion({\n targetId: \"targetId\",\n provider: 42,\n });\n\n // then\n expect(response).resolves.toEqual(Left(new HttpFetchApiError(error)));\n });\n });\n\n describe(\"getFirmwareVersion\", () => {\n let api: ManagerApiDataSource;\n beforeEach(() => {\n api = new AxiosManagerApiDataSource({} as DmkConfig);\n });\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"should return a complete firmware version\", () => {\n // given\n vi.spyOn(axios, \"get\").mockResolvedValue({\n data: mockGetFirmwareVersion,\n });\n\n // when\n const response = api.getFirmwareVersion({\n version: \"versionName\",\n deviceId: 42,\n provider: 21,\n });\n\n // then\n expect(response).resolves.toEqual(Right(mockGetFirmwareVersion));\n });\n it(\"should return an error if the request fails\", () => {\n // given\n const error = new Error(\"fetch error\");\n vi.spyOn(axios, \"get\").mockRejectedValue(error);\n\n // when\n const response = api.getFirmwareVersion({\n version: \"versionName\",\n deviceId: 42,\n provider: 21,\n });\n\n // then\n expect(response).resolves.toEqual(Left(new HttpFetchApiError(error)));\n });\n });\n});\n"],
5
+ "mappings": "wdAAA,IAAAA,EAAkB,oBAClBC,EAA4B,qBAE5BC,EAKO,kDAEPC,EAAkC,8CAElCC,EAA0C,uCAG1C,GAAG,KAAK,OAAO,EAEf,MAAMC,EAAuB,CAC3B,GAAI,GACJ,UAAW,WACb,EAEMC,EAAyB,CAC7B,GAAI,IACJ,MAAO,UACT,EAEA,SAAS,4BAA6B,IAAM,CAC1C,SAAS,aAAc,IAAM,CAC3B,IAAIC,EACJ,WAAW,IAAM,CACfA,EAAM,IAAI,4BAA0B,CAAC,CAAc,CACrD,CAAC,EACD,UAAU,IAAM,CACd,GAAG,cAAc,CACnB,CAAC,EACD,GAAG,uCAAwC,IAAM,CAE/C,MAAMC,EAAO,CAAC,mBAAkB,iCAA+B,EAC/D,GAAG,MAAM,EAAAC,QAAO,KAAK,EAAE,kBAAkB,CAAE,KAAMD,CAAK,CAAC,EAGvD,MAAME,EAAWH,EAAI,WAAW,CAC9B,SAAU,WACV,SAAU,GACV,oBAAqB,qBACvB,CAAC,EAGD,OAAOG,CAAQ,EAAE,SAAS,WAAQ,SAAMF,CAAI,CAAC,CAC/C,CAAC,EACD,GAAG,8CAA+C,IAAM,CAEtD,MAAMG,EAAQ,IAAI,MAAM,aAAa,EACrC,GAAG,MAAM,EAAAF,QAAO,KAAK,EAAE,kBAAkBE,CAAK,EAG9C,MAAMD,EAAWH,EAAI,WAAW,CAC9B,SAAU,WACV,SAAU,GACV,oBAAqB,qBACvB,CAAC,EAGD,OAAOG,CAAQ,EAAE,SAAS,WAAQ,QAAK,IAAI,oBAAkBC,CAAK,CAAC,CAAC,CACtE,CAAC,CACH,CAAC,EACD,SAAS,gBAAiB,IAAM,CAC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AAmB,CACtC,QAAS,cACT,SAAU,GACV,SAAU,EACZ,CAAC,EAGD,OAAOG,CAAQ,EAAE,SAAS,WAAQ,SAAMJ,CAAsB,CAAC,CACjE,CAAC,EACD,GAAG,8CAA+C,IAAM,CAEtD,MAAMK,EAAQ,IAAI,MAAM,aAAa,EACrC,GAAG,MAAM,EAAAF,QAAO,KAAK,EAAE,kBAAkBE,CAAK,EAG9C,MAAMD,EAAWH,EAAI,mBAAmB,CACtC,QAAS,cACT,SAAU,GACV,SAAU,EACZ,CAAC,EAGD,OAAOG,CAAQ,EAAE,SAAS,WAAQ,QAAK,IAAI,oBAAkBC,CAAK,CAAC,CAAC,CACtE,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_axios", "import_purify_ts", "import_data", "import_Errors", "import_AxiosManagerApiDataSource", "mockGetDeviceVersion", "mockGetFirmwareVersion", "api", "apps", "axios", "response", "error", "hashes", "err"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var m=(e,r,o,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of a(r))!c.call(e,t)&&t!==o&&p(e,t,{get:()=>r[t],enumerable:!(i=n(r,t))||i.enumerable});return e};var s=e=>m(p({},"__esModule",{value:!0}),e);var A={};module.exports=s(A);
1
+ "use strict";var i=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var n=(e,r,a,p)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of o(r))!m.call(e,t)&&t!==a&&i(e,t,{get:()=>r[t],enumerable:!(p=s(r,t))||p.enumerable});return e};var A=e=>n(i({},"__esModule",{value:!0}),e);var c={};module.exports=A(c);
2
2
  //# sourceMappingURL=ManagerApiDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/manager-api/data/ManagerApiDataSource.ts"],
4
- "sourcesContent": ["import { type EitherAsync } from \"purify-ts\";\n\nimport { type Application } from \"@internal/manager-api/model/Application\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { type HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\n\n/**\n * Interface representing a data source for the Manager API.\n */\nexport interface ManagerApiDataSource {\n /**\n * Retrieves applications by their hashes.\n *\n * @param hashes - An array of application hashes.\n * @returns EitherAsync containing an array of applications or null values, or an HttpFetchApiError.\n */\n getAppsByHash(\n hashes: string[],\n ): EitherAsync<HttpFetchApiError, Array<Application | null>>;\n\n /**\n * Retrieves the device version for a given target ID and provider.\n *\n * @param targetId - The target ID of the device.\n * @param provider - The provider number.\n * @returns EitherAsync containing the device version or an HttpFetchApiError.\n */\n getDeviceVersion(\n targetId: string,\n provider: number,\n ): EitherAsync<HttpFetchApiError, DeviceVersion>;\n\n /**\n * Retrieves the firmware version for a given version, device ID, and provider.\n *\n * @param version - The firmware version.\n * @param deviceId - The device ID.\n * @param provider - The provider number.\n * @returns EitherAsync containing the final firmware or an HttpFetchApiError.\n */\n getFirmwareVersion(\n version: string,\n deviceId: number,\n provider: number,\n ): EitherAsync<HttpFetchApiError, FinalFirmware>;\n}\n"],
4
+ "sourcesContent": ["import { type EitherAsync } from \"purify-ts\";\n\nimport { type Application } from \"@internal/manager-api/model/Application\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { type HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\nimport {\n type GetAppByHashParams,\n type GetAppListParams,\n type GetDeviceVersionParams,\n type GetFirmwareVersionParams,\n} from \"@internal/manager-api/model/Params\";\n\n/**\n * Interface representing a data source for the Manager API.\n */\nexport interface ManagerApiDataSource {\n /**\n * Retrieves the list of applications for a given target ID, provider, and firmware version.\n *\n * @param params - The parameters for getting the application list.\n * @returns EitherAsync containing an array of applications or an HttpFetchApiError.\n */\n getAppList(\n params: GetAppListParams,\n ): EitherAsync<HttpFetchApiError, Application[]>;\n\n /**\n * Retrieves applications by their hashes.\n *\n * @param hashes - An array of application hashes, can be got from the response of the ListAppsCommand.\n * @returns EitherAsync containing an array of applications or null values, or an HttpFetchApiError.\n */\n getAppsByHash(\n params: GetAppByHashParams,\n ): EitherAsync<HttpFetchApiError, Array<Application | null>>;\n\n /**\n * Retrieves the device version for a given target ID and provider.\n *\n * @param params - The parameters for getting the device version.\n * @returns EitherAsync containing the device version or an HttpFetchApiError.\n */\n getDeviceVersion(\n params: GetDeviceVersionParams,\n ): EitherAsync<HttpFetchApiError, DeviceVersion>;\n\n /**\n * Retrieves the firmware version for a given version, device ID, and provider.\n *\n * @param params - The parameters for getting the firmware version.\n * @returns EitherAsync containing the final firmware or an HttpFetchApiError.\n */\n getFirmwareVersion(\n params: GetFirmwareVersionParams,\n ): EitherAsync<HttpFetchApiError, FinalFirmware>;\n}\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["ManagerApiDataSource_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var t=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var c=(i,n)=>{for(var e in n)t(i,e,{get:n[e],enumerable:!0})},u=(i,n,e,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of a(n))!l.call(i,r)&&r!==e&&t(i,r,{get:()=>n[r],enumerable:!(s=g(n,r))||s.enumerable});return i};var p=i=>u(t({},"__esModule",{value:!0}),i);var d={};c(d,{AppTypeDto:()=>o});module.exports=p(d);var o=(r=>(r.currency="currency",r.plugin="plugin",r.tool="tool",r.swap="swap",r))(o||{});0&&(module.exports={AppTypeDto});
1
+ "use strict";var t=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var u=(e,n)=>{for(var i in n)t(e,i,{get:n[i],enumerable:!0})},c=(e,n,i,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of a(n))!l.call(e,r)&&r!==i&&t(e,r,{get:()=>n[r],enumerable:!(s=g(n,r))||s.enumerable});return e};var p=e=>c(t({},"__esModule",{value:!0}),e);var m={};u(m,{AppTypeDto:()=>o});module.exports=p(m);var o=(r=>(r.currency="currency",r.plugin="plugin",r.tool="tool",r.swap="swap",r))(o||{});0&&(module.exports={AppTypeDto});
2
2
  //# sourceMappingURL=ManagerApiDto.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/manager-api/data/ManagerApiDto.ts"],
4
- "sourcesContent": ["export type Id = number;\n\nexport enum AppTypeDto {\n currency = \"currency\",\n plugin = \"plugin\",\n tool = \"tool\",\n swap = \"swap\",\n}\n\nexport type ApplicationDto = {\n versionId: Id;\n versionName: string;\n versionDisplayName: string;\n version: string;\n currencyId: string;\n description: string;\n applicationType: AppTypeDto;\n dateModified: string;\n icon: string;\n authorName: string;\n supportURL: string;\n contactURL: string;\n sourceURL: string;\n hash: string;\n perso: string;\n parentName: string | null;\n firmware: string;\n firmwareKey: string;\n delete: string;\n deleteKey: string;\n bytes: number;\n warning: string | null;\n isDevTools: boolean;\n};\n"],
4
+ "sourcesContent": ["export type Id = number;\n\nexport enum AppTypeDto {\n currency = \"currency\",\n plugin = \"plugin\",\n tool = \"tool\",\n swap = \"swap\",\n}\n\nexport type ApplicationDto = {\n versionId: Id;\n versionName: string;\n versionDisplayName: string;\n version: string;\n currencyId: string;\n description: string;\n applicationType: AppTypeDto;\n dateModified: string;\n icon: string;\n authorName: string;\n supportURL: string;\n contactURL: string;\n sourceURL: string;\n compatibleWallets: string;\n hash: string;\n perso: string;\n firmware: string;\n firmwareKey: string;\n delete: string;\n deleteKey: string;\n bytes: number;\n warning: string | null;\n isDevTools: boolean;\n category: number;\n parent: number | null;\n parentName: string | null;\n};\n"],
5
5
  "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,IAAA,eAAAC,EAAAH,GAEO,IAAKE,OACVA,EAAA,SAAW,WACXA,EAAA,OAAS,SACTA,EAAA,KAAO,OACPA,EAAA,KAAO,OAJGA,OAAA",
6
6
  "names": ["ManagerApiDto_exports", "__export", "AppTypeDto", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var t=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var g=(a,e)=>{for(var r in e)t(a,r,{get:e[r],enumerable:!0})},c=(a,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of p(e))!s.call(a,i)&&i!==r&&t(a,i,{get:()=>e[i],enumerable:!(n=o(e,i))||n.enumerable});return a};var m=a=>c(t({},"__esModule",{value:!0}),a);var f={};g(f,{AxiosManagerApiDataSource:()=>A});module.exports=m(f);class A{getDeviceVersion=vi.fn();getFirmwareVersion=vi.fn();getAppsByHash=vi.fn()}0&&(module.exports={AxiosManagerApiDataSource});
1
+ "use strict";var t=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var g=(a,e)=>{for(var r in e)t(a,r,{get:e[r],enumerable:!0})},A=(a,e,r,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of o(e))!s.call(a,i)&&i!==r&&t(a,i,{get:()=>e[i],enumerable:!(p=n(e,i))||p.enumerable});return a};var c=a=>A(t({},"__esModule",{value:!0}),a);var m={};g(m,{AxiosManagerApiDataSource:()=>f});module.exports=c(m);class f{getAppList=vi.fn();getDeviceVersion=vi.fn();getFirmwareVersion=vi.fn();getAppsByHash=vi.fn()}0&&(module.exports={AxiosManagerApiDataSource});
2
2
  //# sourceMappingURL=AxiosManagerApiDataSource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.ts"],
4
- "sourcesContent": ["import { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\n\nexport class AxiosManagerApiDataSource implements ManagerApiDataSource {\n getDeviceVersion = vi.fn();\n getFirmwareVersion = vi.fn();\n getAppsByHash = vi.fn();\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAEO,MAAME,CAA0D,CACrE,iBAAmB,GAAG,GAAG,EACzB,mBAAqB,GAAG,GAAG,EAC3B,cAAgB,GAAG,GAAG,CACxB",
4
+ "sourcesContent": ["import { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\n\nexport class AxiosManagerApiDataSource implements ManagerApiDataSource {\n getAppList = vi.fn();\n getDeviceVersion = vi.fn();\n getFirmwareVersion = vi.fn();\n getAppsByHash = vi.fn();\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAEO,MAAME,CAA0D,CACrE,WAAa,GAAG,GAAG,EACnB,iBAAmB,GAAG,GAAG,EACzB,mBAAqB,GAAG,GAAG,EAC3B,cAAgB,GAAG,GAAG,CACxB",
6
6
  "names": ["AxiosManagerApiDataSource_exports", "__export", "AxiosManagerApiDataSource", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var e=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var c=(i,n)=>{for(var t in n)e(i,t,{get:n[t],enumerable:!0})},u=(i,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of a(n))!l.call(i,r)&&r!==t&&e(i,r,{get:()=>n[r],enumerable:!(s=g(n,r))||s.enumerable});return i};var m=i=>u(e({},"__esModule",{value:!0}),i);var p={};c(p,{AppType:()=>o});module.exports=m(p);var o=(r=>(r.currency="currency",r.plugin="plugin",r.tool="tool",r.swap="swap",r))(o||{});0&&(module.exports={AppType});
1
+ "use strict";var e=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var u=(i,n)=>{for(var t in n)e(i,t,{get:n[t],enumerable:!0})},c=(i,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of a(n))!l.call(i,r)&&r!==t&&e(i,r,{get:()=>n[r],enumerable:!(s=g(n,r))||s.enumerable});return i};var m=i=>c(e({},"__esModule",{value:!0}),i);var p={};u(p,{AppType:()=>o});module.exports=m(p);var o=(r=>(r.currency="currency",r.plugin="plugin",r.tool="tool",r.swap="swap",r))(o||{});0&&(module.exports={AppType});
2
2
  //# sourceMappingURL=Application.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/manager-api/model/Application.ts"],
4
- "sourcesContent": ["export enum AppType {\n currency = \"currency\",\n plugin = \"plugin\",\n tool = \"tool\",\n swap = \"swap\",\n}\n\nexport type Application = {\n versionId: number;\n versionName: string;\n versionDisplayName: string;\n version: string;\n currencyId: string;\n description: string;\n applicationType: AppType;\n dateModified: string;\n icon: string;\n authorName: string;\n supportURL: string;\n contactURL: string;\n sourceURL: string;\n hash: string;\n perso: string;\n parentName: string | null;\n firmware: string;\n firmwareKey: string;\n delete: string;\n deleteKey: string;\n bytes: number;\n warning: string | null;\n isDevTools: boolean;\n};\n"],
4
+ "sourcesContent": ["export enum AppType {\n currency = \"currency\",\n plugin = \"plugin\",\n tool = \"tool\",\n swap = \"swap\",\n}\n\nexport type Application = {\n versionId: number;\n versionName: string;\n versionDisplayName: string;\n version: string;\n currencyId: string;\n description: string;\n applicationType: AppType;\n dateModified: string;\n icon: string;\n authorName: string;\n supportURL: string;\n contactURL: string;\n sourceURL: string;\n compatibleWallets: string;\n hash: string;\n perso: string;\n firmware: string;\n firmwareKey: string;\n delete: string;\n deleteKey: string;\n bytes: number;\n warning: string | null;\n isDevTools: boolean;\n category: number;\n parent: number | null;\n parentName: string | null;\n};\n"],
5
5
  "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAO,IAAKE,OACVA,EAAA,SAAW,WACXA,EAAA,OAAS,SACTA,EAAA,KAAO,OACPA,EAAA,KAAO,OAJGA,OAAA",
6
6
  "names": ["Application_exports", "__export", "AppType", "__toCommonJS"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ "use strict";var s=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var o=(r,e,a,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of n(e))!m.call(r,t)&&t!==a&&s(r,t,{get:()=>e[t],enumerable:!(i=p(e,t))||i.enumerable});return r};var d=r=>o(s({},"__esModule",{value:!0}),r);var g={};module.exports=d(g);
2
+ //# sourceMappingURL=Params.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/internal/manager-api/model/Params.ts"],
4
+ "sourcesContent": ["/**\n * Parameters required to get the list of applications.\n *\n * @property targetId - The unique identifier of the target device, can be got from the response of the GetOsVersionCommand.\n * @property provider - The provider identifier.\n * @property firmwareVersionName - The firmware version of the device, can be obtained from the response of the GetOsVersionCommand, property name `seVersion`.\n */\nexport type GetAppListParams = {\n targetId: string;\n provider: number;\n firmwareVersionName: string;\n};\n\n/**\n * Parameters required to get applications by their hashes.\n *\n * @property hashes - An array of application hashes.\n */\nexport type GetAppByHashParams = {\n hashes: string[];\n};\n\n/**\n * Parameters required to get the device version.\n *\n * @property targetId - The unique identifier of the target device.\n * @property provider - The provider identifier.\n */\nexport type GetDeviceVersionParams = {\n targetId: string;\n provider: number;\n};\n\n/**\n * Parameters required to get the firmware version of a device.\n *\n * @property version - The version of the firmware, can be got from the response of the getDeviceVersion HTTP request.\n * @property deviceId - The unique identifier of the device, can be got from the GetOsVersionCommand response.\n * @property provider - The identifier of the firmware provider.\n */\nexport type GetFirmwareVersionParams = {\n version: string;\n deviceId: number;\n provider: number;\n};\n"],
5
+ "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
+ "names": ["Params_exports", "__toCommonJS"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var V=(s,r)=>{for(var t in r)p(s,t,{get:r[t],enumerable:!0})},d=(s,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of l(r))!y.call(s,e)&&e!==t&&p(s,e,{get:()=>r[e],enumerable:!(o=u(r,e))||o.enumerable});return s};var S=s=>d(p({},"__esModule",{value:!0}),s),g=(s,r,t,o)=>{for(var e=o>1?void 0:o?u(r,t):r,i=s.length-1,c;i>=0;i--)(c=s[i])&&(e=(o?c(r,t,e):c(e))||e);return o&&e&&p(r,t,e),e},h=(s,r)=>(t,o)=>r(t,o,s);var F={};V(F,{DefaultManagerApiService:()=>n});module.exports=S(F);var a=require("inversify"),A=require("purify-ts"),f=require("../../manager-api/di/managerApiTypes"),m=require("../../manager-api/model/Errors");let n=class{constructor(r){this.dataSource=r}getDeviceVersion(r,t){return this.dataSource.getDeviceVersion(r.targetId.toString(),t)}getFirmwareVersion(r,t,o){return this.dataSource.getFirmwareVersion(r.seVersion,t.id,o)}getAppsByHash(r){const t=r.reduce((o,e)=>e.appFullHash?o.concat(e.appFullHash):o,[]);return(0,A.EitherAsync)(async({fromPromise:o,throwE:e})=>{if(t.length===0)return[];try{return await o(this.dataSource.getAppsByHash(t))}catch(i){return i instanceof m.HttpFetchApiError?e(i):e(new m.HttpFetchApiError(i))}})}};n=g([(0,a.injectable)(),h(0,(0,a.inject)(f.managerApiTypes.ManagerApiDataSource))],n);0&&(module.exports={DefaultManagerApiService});
1
+ "use strict";var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var G=(a,r)=>{for(var e in r)p(a,e,{get:r[e],enumerable:!0})},f=(a,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of V(r))!d.call(a,t)&&t!==e&&p(a,t,{get:()=>r[t],enumerable:!(s=y(r,t))||s.enumerable});return a};var S=a=>f(p({},"__esModule",{value:!0}),a),A=(a,r,e,s)=>{for(var t=s>1?void 0:s?y(r,e):r,i=a.length-1,m;i>=0;i--)(m=a[i])&&(t=(s?m(r,e,t):m(t))||t);return s&&t&&p(r,e,t),t},g=(a,r)=>(e,s)=>r(e,s,a);var P={};G(P,{DefaultManagerApiService:()=>o});module.exports=S(P);var n=require("inversify"),h=require("purify-ts"),u=require("../../manager-api/di/managerApiTypes"),c=require("../../manager-api/model/Errors");let o=class{constructor(r){this.dataSource=r}getAppList(r,e){const s={targetId:r.targetId.toString(),provider:e,firmwareVersionName:r.seVersion};return this.dataSource.getAppList(s)}getDeviceVersion(r,e){const s={targetId:r.targetId.toString(),provider:e};return this.dataSource.getDeviceVersion(s)}getFirmwareVersion(r,e,s){const t={version:r.seVersion,deviceId:e.id,provider:s};return this.dataSource.getFirmwareVersion(t)}getAppsByHash(r){const e={hashes:r};return(0,h.EitherAsync)(async({fromPromise:s,throwE:t})=>{if(e.hashes.length===0)return[];try{return await s(this.dataSource.getAppsByHash(e))}catch(i){return i instanceof c.HttpFetchApiError?t(i):t(new c.HttpFetchApiError(i))}})}};o=A([(0,n.injectable)(),g(0,(0,n.inject)(u.managerApiTypes.ManagerApiDataSource))],o);0&&(module.exports={DefaultManagerApiService});
2
2
  //# sourceMappingURL=DefaultManagerApiService.js.map