@dronedeploy/rocos-js-sdk 3.0.1-alpha.9 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +59 -29
- package/cjs/IRocosSDK.d.ts +4 -3
- package/cjs/RocosSDK.d.ts +19 -7
- package/cjs/RocosSDK.js +31 -10
- package/cjs/api/streams/caller/CallerStream.js +5 -2
- package/cjs/api/streams/caller/CallerStreamNode.js +2 -1
- package/cjs/api/streams/command/CommandStream.js +5 -2
- package/cjs/api/streams/command/CommandStreamNode.js +2 -1
- package/cjs/api/streams/control/ControlStream.js +5 -2
- package/cjs/api/streams/control/ControlStreamAbstract.d.ts +1 -1
- package/cjs/api/streams/control/ControlStreamNode.js +2 -1
- package/cjs/api/streams/fileAccessor/FileAccessorStream.js +4 -1
- package/cjs/api/streams/fileAccessor/FileAccessorStreamNode.js +3 -1
- package/cjs/api/streams/search/SearchStream.js +5 -2
- package/cjs/api/streams/search/SearchStreamNode.js +2 -1
- package/cjs/api/streams/telemetry/TelemetryStream.js +4 -1
- package/cjs/api/streams/telemetry/TelemetryStreamAbstract.d.ts +1 -1
- package/cjs/api/streams/telemetry/TelemetryStreamNode.js +2 -1
- package/cjs/api/streams/webRTCSignalling/WebRTCSignallingStream.js +5 -2
- package/cjs/constants/api.d.ts +31 -15
- package/cjs/constants/api.js +35 -18
- package/cjs/helpers/cleanObject.js +4 -1
- package/cjs/helpers/getUniqueConfigKey.d.ts +6 -2
- package/cjs/helpers/getUniqueConfigKey.js +7 -2
- package/cjs/helpers/index.d.ts +1 -0
- package/cjs/helpers/index.js +1 -0
- package/cjs/helpers/kscript/Context.d.ts +34 -0
- package/cjs/helpers/kscript/Context.js +52 -0
- package/cjs/helpers/kscript/index.d.ts +1 -0
- package/cjs/helpers/kscript/index.js +27 -0
- package/cjs/helpers/kscript/kscript.d.ts +6 -0
- package/cjs/helpers/kscript/kscript.js +115 -0
- package/cjs/helpers/kscript/nodes/Identifier.d.ts +12 -0
- package/cjs/helpers/kscript/nodes/Identifier.js +20 -0
- package/cjs/helpers/kscript/nodes/Literal.d.ts +11 -0
- package/cjs/helpers/kscript/nodes/Literal.js +22 -0
- package/cjs/helpers/kscript/nodes/Node.d.ts +9 -0
- package/cjs/helpers/kscript/nodes/Node.js +15 -0
- package/cjs/helpers/kscript/nodes/Program.d.ts +11 -0
- package/cjs/helpers/kscript/nodes/Program.js +24 -0
- package/cjs/helpers/kscript/nodes/TemplateLiteral.d.ts +23 -0
- package/cjs/helpers/kscript/nodes/TemplateLiteral.js +35 -0
- package/cjs/helpers/kscript/nodes/expressions/ArrayExpression.d.ts +7 -0
- package/cjs/helpers/kscript/nodes/expressions/ArrayExpression.js +31 -0
- package/cjs/helpers/kscript/nodes/expressions/ArrowFunctionExpression.d.ts +14 -0
- package/cjs/helpers/kscript/nodes/expressions/ArrowFunctionExpression.js +40 -0
- package/cjs/helpers/kscript/nodes/expressions/BinaryExpression.d.ts +16 -0
- package/cjs/helpers/kscript/nodes/expressions/BinaryExpression.js +104 -0
- package/cjs/helpers/kscript/nodes/expressions/CallExpression.d.ts +8 -0
- package/cjs/helpers/kscript/nodes/expressions/CallExpression.js +38 -0
- package/cjs/helpers/kscript/nodes/expressions/ChainExpression.d.ts +16 -0
- package/cjs/helpers/kscript/nodes/expressions/ChainExpression.js +25 -0
- package/cjs/helpers/kscript/nodes/expressions/ConditionalExpression.d.ts +14 -0
- package/cjs/helpers/kscript/nodes/expressions/ConditionalExpression.js +30 -0
- package/cjs/helpers/kscript/nodes/expressions/ExpressionStatement.d.ts +7 -0
- package/cjs/helpers/kscript/nodes/expressions/ExpressionStatement.js +18 -0
- package/cjs/helpers/kscript/nodes/expressions/LogicalExpression.d.ts +10 -0
- package/cjs/helpers/kscript/nodes/expressions/LogicalExpression.js +47 -0
- package/cjs/helpers/kscript/nodes/expressions/MemberExpression.d.ts +44 -0
- package/cjs/helpers/kscript/nodes/expressions/MemberExpression.js +98 -0
- package/cjs/helpers/kscript/nodes/expressions/ObjectExpression.d.ts +11 -0
- package/cjs/helpers/kscript/nodes/expressions/ObjectExpression.js +59 -0
- package/cjs/helpers/kscript/nodes/expressions/UnaryExpression.d.ts +12 -0
- package/cjs/helpers/kscript/nodes/expressions/UnaryExpression.js +44 -0
- package/cjs/helpers/kscript/nodes/expressions/index.d.ts +11 -0
- package/cjs/helpers/kscript/nodes/expressions/index.js +28 -0
- package/cjs/helpers/kscript/nodes/index.d.ts +4 -0
- package/cjs/helpers/kscript/nodes/index.js +10 -0
- package/cjs/helpers/kscript/nodes/nodeTypes.d.ts +33 -0
- package/cjs/helpers/kscript/nodes/nodeTypes.js +29 -0
- package/cjs/helpers/kscript/utils.d.ts +4 -0
- package/cjs/helpers/kscript/utils.js +15 -0
- package/cjs/helpers/websandbox/connection.d.ts +2 -1
- package/cjs/helpers/websandbox/connection.js +6 -5
- package/cjs/helpers/websandbox/frame/frame.js +4 -1
- package/cjs/helpers/websandbox/frame/frame.source.js +1 -1
- package/cjs/helpers/websandbox/frame/worker/manager.d.ts +8 -4
- package/cjs/helpers/websandbox/frame/worker/manager.js +32 -14
- package/cjs/helpers/websandbox/frame/worker/worker.source.js +1 -1
- package/cjs/helpers/websandbox/sandbox.d.ts +1 -1
- package/cjs/helpers/websandbox/sandbox.js +7 -7
- package/cjs/models/IConnectedCallsign.d.ts +10 -0
- package/cjs/models/IConnectedCallsign.js +8 -0
- package/cjs/models/RocosError.d.ts +3 -0
- package/cjs/models/RocosError.js +3 -0
- package/cjs/models/ServiceEnum.d.ts +20 -17
- package/cjs/models/ServiceEnum.js +20 -17
- package/cjs/models/TelemetryStatus.d.ts +12 -0
- package/cjs/models/TelemetryStatus.js +17 -0
- package/cjs/models/Token.d.ts +2 -2
- package/cjs/models/Token.js +5 -5
- package/cjs/models/asset-storage/{AssetModelItem.d.ts → AssetItem.d.ts} +2 -0
- package/cjs/models/device-credentials/DeviceCredentials.d.ts +61 -0
- package/cjs/models/device-credentials/DeviceCredentials.js +2 -0
- package/cjs/models/graph/Position.d.ts +6 -0
- package/cjs/models/graph/Position.js +2 -0
- package/cjs/models/graph/Quaternion.d.ts +6 -0
- package/cjs/models/graph/Quaternion.js +2 -0
- package/cjs/models/graph/Vector3.d.ts +5 -0
- package/cjs/models/graph/Vector3.js +2 -0
- package/cjs/models/graph/index.d.ts +3 -0
- package/cjs/models/graph/index.js +19 -0
- package/cjs/models/index.d.ts +9 -2
- package/cjs/models/index.js +9 -2
- package/cjs/models/integrations/Location.d.ts +24 -0
- package/cjs/models/integrations/Location.js +2 -0
- package/cjs/models/integrations/PaginatedResults.d.ts +4 -0
- package/cjs/models/integrations/PaginatedResults.js +2 -0
- package/cjs/models/maps/Panorama.d.ts +12 -21
- package/cjs/models/projects/ExternalProject.d.ts +10 -0
- package/cjs/models/projects/ExternalProject.js +2 -0
- package/cjs/models/projects/NewProjectRequest.d.ts +8 -0
- package/cjs/models/projects/NewProjectRequest.js +2 -0
- package/cjs/models/target/Target.d.ts +30 -0
- package/cjs/models/target/Target.js +15 -0
- package/cjs/node/RocosSDKNode.d.ts +1 -5
- package/cjs/node/RocosSDKNode.js +9 -9
- package/cjs/services/AssetStorageService.d.ts +9 -1
- package/cjs/services/AssetStorageService.js +12 -1
- package/cjs/services/AuthService.d.ts +12 -1
- package/cjs/services/AuthService.js +25 -1
- package/cjs/services/DeviceCredentialsService.d.ts +15 -0
- package/cjs/services/DeviceCredentialsService.js +56 -0
- package/cjs/services/EnvironmentService.d.ts +34 -0
- package/cjs/services/EnvironmentService.js +56 -0
- package/cjs/services/EvaluatorService.js +1 -1
- package/cjs/services/IntegrationService.d.ts +7 -1
- package/cjs/services/IntegrationService.js +8 -0
- package/cjs/services/MapService.d.ts +18 -8
- package/cjs/services/MapService.js +37 -19
- package/cjs/services/ProfileService.d.ts +24 -0
- package/cjs/services/ProfileService.js +34 -0
- package/cjs/services/ProjectService.d.ts +7 -2
- package/cjs/services/ProjectService.js +7 -3
- package/cjs/services/RTPWebRTCService.d.ts +6 -1
- package/cjs/services/RTPWebRTCService.js +10 -2
- package/cjs/services/RobotService.d.ts +3 -1
- package/cjs/services/RobotService.js +6 -0
- package/cjs/services/SpotProvisioningService.d.ts +1 -1
- package/cjs/services/SpotProvisioningServiceNode.d.ts +1 -1
- package/cjs/services/TargetService.d.ts +17 -0
- package/cjs/services/TargetService.js +66 -0
- package/cjs/services/TelemetryService.d.ts +10 -1
- package/cjs/services/TelemetryService.js +27 -5
- package/cjs/services/WorkflowService.d.ts +18 -8
- package/cjs/services/WorkflowService.js +37 -11
- package/cjs/services/index.d.ts +11 -9
- package/cjs/services/index.js +11 -9
- package/cjs/store/RocosStore.d.ts +1 -2
- package/esm/IRocosSDK.d.ts +4 -3
- package/esm/RocosSDK.d.ts +19 -7
- package/esm/RocosSDK.js +32 -11
- package/esm/api/streams/caller/CallerStream.js +5 -2
- package/esm/api/streams/caller/CallerStreamNode.js +2 -1
- package/esm/api/streams/command/CommandStream.js +5 -2
- package/esm/api/streams/command/CommandStreamNode.js +2 -1
- package/esm/api/streams/control/ControlStream.js +5 -2
- package/esm/api/streams/control/ControlStreamAbstract.d.ts +1 -1
- package/esm/api/streams/control/ControlStreamNode.js +2 -1
- package/esm/api/streams/fileAccessor/FileAccessorStream.js +4 -1
- package/esm/api/streams/fileAccessor/FileAccessorStreamNode.js +3 -1
- package/esm/api/streams/search/SearchStream.js +5 -2
- package/esm/api/streams/search/SearchStreamNode.js +2 -1
- package/esm/api/streams/telemetry/TelemetryStream.js +4 -1
- package/esm/api/streams/telemetry/TelemetryStreamAbstract.d.ts +1 -1
- package/esm/api/streams/telemetry/TelemetryStreamNode.js +2 -1
- package/esm/api/streams/webRTCSignalling/WebRTCSignallingStream.js +5 -2
- package/esm/constants/api.d.ts +31 -15
- package/esm/constants/api.js +31 -15
- package/esm/helpers/cleanObject.js +4 -1
- package/esm/helpers/getUniqueConfigKey.d.ts +6 -2
- package/esm/helpers/getUniqueConfigKey.js +7 -2
- package/esm/helpers/index.d.ts +1 -0
- package/esm/helpers/index.js +1 -0
- package/esm/helpers/kscript/Context.d.ts +34 -0
- package/esm/helpers/kscript/Context.js +49 -0
- package/esm/helpers/kscript/index.d.ts +1 -0
- package/esm/helpers/kscript/index.js +1 -0
- package/esm/helpers/kscript/kscript.d.ts +6 -0
- package/esm/helpers/kscript/kscript.js +107 -0
- package/esm/helpers/kscript/nodes/Identifier.d.ts +12 -0
- package/esm/helpers/kscript/nodes/Identifier.js +14 -0
- package/esm/helpers/kscript/nodes/Literal.d.ts +11 -0
- package/esm/helpers/kscript/nodes/Literal.js +16 -0
- package/esm/helpers/kscript/nodes/Node.d.ts +9 -0
- package/esm/helpers/kscript/nodes/Node.js +12 -0
- package/esm/helpers/kscript/nodes/Program.d.ts +11 -0
- package/esm/helpers/kscript/nodes/Program.js +18 -0
- package/esm/helpers/kscript/nodes/TemplateLiteral.d.ts +23 -0
- package/esm/helpers/kscript/nodes/TemplateLiteral.js +29 -0
- package/esm/helpers/kscript/nodes/expressions/ArrayExpression.d.ts +7 -0
- package/esm/helpers/kscript/nodes/expressions/ArrayExpression.js +25 -0
- package/esm/helpers/kscript/nodes/expressions/ArrowFunctionExpression.d.ts +14 -0
- package/esm/helpers/kscript/nodes/expressions/ArrowFunctionExpression.js +34 -0
- package/esm/helpers/kscript/nodes/expressions/BinaryExpression.d.ts +16 -0
- package/esm/helpers/kscript/nodes/expressions/BinaryExpression.js +98 -0
- package/esm/helpers/kscript/nodes/expressions/CallExpression.d.ts +8 -0
- package/esm/helpers/kscript/nodes/expressions/CallExpression.js +32 -0
- package/esm/helpers/kscript/nodes/expressions/ChainExpression.d.ts +16 -0
- package/esm/helpers/kscript/nodes/expressions/ChainExpression.js +19 -0
- package/esm/helpers/kscript/nodes/expressions/ConditionalExpression.d.ts +14 -0
- package/esm/helpers/kscript/nodes/expressions/ConditionalExpression.js +24 -0
- package/esm/helpers/kscript/nodes/expressions/ExpressionStatement.d.ts +7 -0
- package/esm/helpers/kscript/nodes/expressions/ExpressionStatement.js +12 -0
- package/esm/helpers/kscript/nodes/expressions/LogicalExpression.d.ts +10 -0
- package/esm/helpers/kscript/nodes/expressions/LogicalExpression.js +41 -0
- package/esm/helpers/kscript/nodes/expressions/MemberExpression.d.ts +44 -0
- package/esm/helpers/kscript/nodes/expressions/MemberExpression.js +92 -0
- package/esm/helpers/kscript/nodes/expressions/ObjectExpression.d.ts +11 -0
- package/esm/helpers/kscript/nodes/expressions/ObjectExpression.js +53 -0
- package/esm/helpers/kscript/nodes/expressions/UnaryExpression.d.ts +12 -0
- package/esm/helpers/kscript/nodes/expressions/UnaryExpression.js +38 -0
- package/esm/helpers/kscript/nodes/expressions/index.d.ts +11 -0
- package/esm/helpers/kscript/nodes/expressions/index.js +11 -0
- package/esm/helpers/kscript/nodes/index.d.ts +4 -0
- package/esm/helpers/kscript/nodes/index.js +3 -0
- package/esm/helpers/kscript/nodes/nodeTypes.d.ts +33 -0
- package/esm/helpers/kscript/nodes/nodeTypes.js +24 -0
- package/esm/helpers/kscript/utils.d.ts +4 -0
- package/esm/helpers/kscript/utils.js +11 -0
- package/esm/helpers/websandbox/connection.d.ts +2 -1
- package/esm/helpers/websandbox/connection.js +6 -5
- package/esm/helpers/websandbox/frame/frame.js +4 -1
- package/esm/helpers/websandbox/frame/frame.source.js +1 -1
- package/esm/helpers/websandbox/frame/worker/manager.d.ts +8 -4
- package/esm/helpers/websandbox/frame/worker/manager.js +32 -14
- package/esm/helpers/websandbox/frame/worker/worker.source.js +1 -1
- package/esm/helpers/websandbox/sandbox.d.ts +1 -1
- package/esm/helpers/websandbox/sandbox.js +7 -7
- package/esm/models/IConnectedCallsign.d.ts +10 -0
- package/esm/models/IConnectedCallsign.js +5 -0
- package/esm/models/RocosError.d.ts +3 -0
- package/esm/models/RocosError.js +3 -0
- package/esm/models/ServiceEnum.d.ts +20 -17
- package/esm/models/ServiceEnum.js +20 -17
- package/esm/models/TelemetryStatus.d.ts +12 -0
- package/esm/models/TelemetryStatus.js +14 -0
- package/esm/models/Token.d.ts +2 -2
- package/esm/models/Token.js +5 -5
- package/esm/models/asset-storage/{AssetModelItem.d.ts → AssetItem.d.ts} +2 -0
- package/esm/models/device-credentials/DeviceCredentials.d.ts +61 -0
- package/esm/models/graph/Position.d.ts +6 -0
- package/esm/models/graph/Quaternion.d.ts +6 -0
- package/esm/models/graph/Vector3.d.ts +5 -0
- package/esm/models/graph/index.d.ts +3 -0
- package/esm/models/graph/index.js +3 -0
- package/esm/models/index.d.ts +9 -2
- package/esm/models/index.js +9 -2
- package/esm/models/integrations/Location.d.ts +24 -0
- package/esm/models/integrations/PaginatedResults.d.ts +4 -0
- package/esm/models/maps/Panorama.d.ts +12 -21
- package/esm/models/projects/ExternalProject.d.ts +10 -0
- package/esm/models/projects/NewProjectRequest.d.ts +8 -0
- package/esm/models/target/Target.d.ts +30 -0
- package/esm/models/target/Target.js +9 -0
- package/esm/node/RocosSDKNode.d.ts +1 -5
- package/esm/node/RocosSDKNode.js +10 -10
- package/esm/services/AssetStorageService.d.ts +9 -1
- package/esm/services/AssetStorageService.js +13 -2
- package/esm/services/AuthService.d.ts +12 -1
- package/esm/services/AuthService.js +25 -1
- package/esm/services/BaseServiceAbstract.js +1 -1
- package/esm/services/DeviceCredentialsService.d.ts +15 -0
- package/esm/services/DeviceCredentialsService.js +52 -0
- package/esm/services/EnvironmentService.d.ts +34 -0
- package/esm/services/EnvironmentService.js +52 -0
- package/esm/services/EvaluatorService.js +1 -1
- package/esm/services/IntegrationService.d.ts +7 -1
- package/esm/services/IntegrationService.js +10 -2
- package/esm/services/MapService.d.ts +18 -8
- package/esm/services/MapService.js +38 -20
- package/esm/services/ProfileService.d.ts +24 -0
- package/esm/services/ProfileService.js +35 -1
- package/esm/services/ProjectService.d.ts +7 -2
- package/esm/services/ProjectService.js +9 -5
- package/esm/services/RTPWebRTCService.d.ts +6 -1
- package/esm/services/RTPWebRTCService.js +10 -2
- package/esm/services/RobotService.d.ts +3 -1
- package/esm/services/RobotService.js +8 -2
- package/esm/services/SpotProvisioningService.d.ts +1 -1
- package/esm/services/SpotProvisioningServiceNode.d.ts +1 -1
- package/esm/services/TargetService.d.ts +17 -0
- package/esm/services/TargetService.js +62 -0
- package/esm/services/TelemetryService.d.ts +10 -1
- package/esm/services/TelemetryService.js +28 -6
- package/esm/services/WorkflowService.d.ts +18 -8
- package/esm/services/WorkflowService.js +38 -12
- package/esm/services/index.d.ts +11 -9
- package/esm/services/index.js +11 -9
- package/esm/store/RocosStore.d.ts +1 -2
- package/package.json +2 -2
- package/cjs/helpers/cleanObject.spec.js +0 -55
- package/cjs/helpers/flattenObject.spec.js +0 -31
- package/cjs/helpers/flattenOneOf.spec.js +0 -159
- package/cjs/helpers/formatServiceUrl.spec.js +0 -18
- package/cjs/helpers/getSha256Hex.spec.js +0 -19
- package/cjs/helpers/getSha256HexNode.spec.js +0 -10
- package/cjs/helpers/getURLSearchParams.spec.js +0 -21
- package/cjs/helpers/nanosecondToMillisecond.spec.js +0 -22
- package/cjs/helpers/splitRobotTopic.spec.js +0 -53
- package/cjs/helpers/standardDeviation.spec.d.ts +0 -1
- package/cjs/helpers/standardDeviation.spec.js +0 -13
- package/cjs/helpers/websandbox/frame/worker/manager.spec.d.ts +0 -4
- package/cjs/helpers/websandbox/frame/worker/manager.spec.js +0 -132
- package/cjs/models/CallsignStatus.d.ts +0 -6
- package/cjs/models/CallsignStatus.js +0 -10
- package/cjs/models/ExternalProject.d.ts +0 -6
- package/cjs/models/ExternalProject.js +0 -6
- package/cjs/models/Token.spec.d.ts +0 -1
- package/cjs/models/Token.spec.js +0 -110
- package/cjs/services/AuthService.spec.d.ts +0 -1
- package/cjs/services/AuthService.spec.js +0 -165
- package/cjs/services/CallerService.spec.d.ts +0 -1
- package/cjs/services/CallerService.spec.js +0 -229
- package/cjs/services/FunctionService.d.ts +0 -68
- package/cjs/services/FunctionService.js +0 -103
- package/cjs/services/PlatformTimeService.spec.d.ts +0 -1
- package/cjs/services/PlatformTimeService.spec.js +0 -182
- package/cjs/services/RTPWebRTCService.spec.d.ts +0 -4
- package/cjs/services/RTPWebRTCService.spec.js +0 -171
- package/cjs/services/TelemetryService.spec.d.ts +0 -1
- package/cjs/services/TelemetryService.spec.js +0 -39
- package/esm/helpers/cleanObject.spec.d.ts +0 -1
- package/esm/helpers/cleanObject.spec.js +0 -53
- package/esm/helpers/flattenObject.spec.d.ts +0 -1
- package/esm/helpers/flattenObject.spec.js +0 -29
- package/esm/helpers/flattenOneOf.spec.d.ts +0 -1
- package/esm/helpers/flattenOneOf.spec.js +0 -157
- package/esm/helpers/formatServiceUrl.spec.d.ts +0 -1
- package/esm/helpers/formatServiceUrl.spec.js +0 -16
- package/esm/helpers/getSha256Hex.spec.d.ts +0 -1
- package/esm/helpers/getSha256Hex.spec.js +0 -14
- package/esm/helpers/getSha256HexNode.spec.d.ts +0 -1
- package/esm/helpers/getSha256HexNode.spec.js +0 -8
- package/esm/helpers/getURLSearchParams.spec.d.ts +0 -1
- package/esm/helpers/getURLSearchParams.spec.js +0 -19
- package/esm/helpers/nanosecondToMillisecond.spec.d.ts +0 -1
- package/esm/helpers/nanosecondToMillisecond.spec.js +0 -20
- package/esm/helpers/splitRobotTopic.spec.d.ts +0 -1
- package/esm/helpers/splitRobotTopic.spec.js +0 -51
- package/esm/helpers/standardDeviation.spec.d.ts +0 -1
- package/esm/helpers/standardDeviation.spec.js +0 -11
- package/esm/helpers/websandbox/frame/worker/manager.spec.d.ts +0 -4
- package/esm/helpers/websandbox/frame/worker/manager.spec.js +0 -127
- package/esm/models/CallsignStatus.d.ts +0 -6
- package/esm/models/CallsignStatus.js +0 -7
- package/esm/models/ExternalProject.d.ts +0 -6
- package/esm/models/ExternalProject.js +0 -2
- package/esm/models/Token.spec.d.ts +0 -1
- package/esm/models/Token.spec.js +0 -108
- package/esm/models/asset-storage/AssetModelItem.js +0 -1
- package/esm/services/AuthService.spec.d.ts +0 -1
- package/esm/services/AuthService.spec.js +0 -163
- package/esm/services/CallerService.spec.d.ts +0 -1
- package/esm/services/CallerService.spec.js +0 -227
- package/esm/services/FunctionService.d.ts +0 -68
- package/esm/services/FunctionService.js +0 -99
- package/esm/services/PlatformTimeService.spec.d.ts +0 -1
- package/esm/services/PlatformTimeService.spec.js +0 -180
- package/esm/services/RTPWebRTCService.spec.d.ts +0 -4
- package/esm/services/RTPWebRTCService.spec.js +0 -169
- package/esm/services/TelemetryService.spec.d.ts +0 -1
- package/esm/services/TelemetryService.spec.js +0 -37
- /package/cjs/models/asset-storage/{AssetModelItem.js → AssetItem.js} +0 -0
- /package/{cjs/helpers/cleanObject.spec.d.ts → esm/models/asset-storage/AssetItem.js} +0 -0
- /package/{cjs/helpers/flattenObject.spec.d.ts → esm/models/device-credentials/DeviceCredentials.js} +0 -0
- /package/{cjs/helpers/flattenOneOf.spec.d.ts → esm/models/graph/Position.js} +0 -0
- /package/{cjs/helpers/formatServiceUrl.spec.d.ts → esm/models/graph/Quaternion.js} +0 -0
- /package/{cjs/helpers/getSha256Hex.spec.d.ts → esm/models/graph/Vector3.js} +0 -0
- /package/{cjs/helpers/getSha256HexNode.spec.d.ts → esm/models/integrations/Location.js} +0 -0
- /package/{cjs/helpers/getURLSearchParams.spec.d.ts → esm/models/integrations/PaginatedResults.js} +0 -0
- /package/{cjs/helpers/nanosecondToMillisecond.spec.d.ts → esm/models/projects/ExternalProject.js} +0 -0
- /package/{cjs/helpers/splitRobotTopic.spec.d.ts → esm/models/projects/NewProjectRequest.js} +0 -0
@@ -1,18 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const formatServiceUrl_1 = require("./formatServiceUrl");
|
4
|
-
describe('formatServiceUrl', () => {
|
5
|
-
const url = 'https://{url}/admin/users/{test}/invitations';
|
6
|
-
it('should format url', () => {
|
7
|
-
let newUrl = (0, formatServiceUrl_1.formatServiceUrl)(url, { url: 'test.com', test: 'me' });
|
8
|
-
expect(newUrl).toEqual('https://test.com/admin/users/me/invitations');
|
9
|
-
newUrl = (0, formatServiceUrl_1.formatServiceUrl)(url, { url: 'test2.com', test: 'me2' });
|
10
|
-
expect(newUrl).toEqual('https://test2.com/admin/users/me2/invitations');
|
11
|
-
});
|
12
|
-
it('should format insecure url', () => {
|
13
|
-
let newUrl = (0, formatServiceUrl_1.formatServiceUrl)(url, { url: 'test.com', test: 'me' }, true);
|
14
|
-
expect(newUrl).toEqual('http://test.com/admin/users/me/invitations');
|
15
|
-
newUrl = (0, formatServiceUrl_1.formatServiceUrl)(url, { url: 'test2.com', test: 'me2' }, true);
|
16
|
-
expect(newUrl).toEqual('http://test2.com/admin/users/me2/invitations');
|
17
|
-
});
|
18
|
-
});
|
@@ -1,19 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
const crypto_1 = __importDefault(require("crypto"));
|
7
|
-
const getSha256Hex_1 = require("./getSha256Hex");
|
8
|
-
Object.defineProperty(globalThis, 'crypto', {
|
9
|
-
value: {
|
10
|
-
subtle: crypto_1.default.webcrypto.subtle,
|
11
|
-
},
|
12
|
-
});
|
13
|
-
describe('getSha256Hex', () => {
|
14
|
-
it('should return the correct SHA-256 hash', async () => {
|
15
|
-
const buffer = new TextEncoder().encode('Hello, World!');
|
16
|
-
const hash = await (0, getSha256Hex_1.getSha256Hex)(buffer);
|
17
|
-
expect(hash).toBe('dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f');
|
18
|
-
});
|
19
|
-
});
|
@@ -1,10 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const getSha256HexNode_1 = require("./getSha256HexNode");
|
4
|
-
describe('getSha256HexNode', () => {
|
5
|
-
it('should return the correct SHA-256 hash', async () => {
|
6
|
-
const buffer = new TextEncoder().encode('Hello, World!');
|
7
|
-
const hash = await (0, getSha256HexNode_1.getSha256HexNode)(buffer);
|
8
|
-
expect(hash).toBe('dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f');
|
9
|
-
});
|
10
|
-
});
|
@@ -1,21 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const getURLSearchParams_1 = require("./getURLSearchParams");
|
4
|
-
describe('getURLSearchParams', () => {
|
5
|
-
it('Should return the original param if URLSearchParams', () => {
|
6
|
-
const param = new URLSearchParams();
|
7
|
-
const searchParam = (0, getURLSearchParams_1.getURLSearchParams)(param);
|
8
|
-
expect(searchParam).toBe(param);
|
9
|
-
});
|
10
|
-
it('Should a new URLSearchParams ', () => {
|
11
|
-
const param = {
|
12
|
-
foo: 'bar',
|
13
|
-
bar: true,
|
14
|
-
foobar: 123,
|
15
|
-
};
|
16
|
-
const searchParam = (0, getURLSearchParams_1.getURLSearchParams)(param);
|
17
|
-
expect(searchParam.get('foo')).toBe('bar');
|
18
|
-
expect(searchParam.get('bar')).toBe('true');
|
19
|
-
expect(searchParam.get('foobar')).toBe('123');
|
20
|
-
});
|
21
|
-
});
|
@@ -1,22 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const nanosecondToMillisecond_1 = require("./nanosecondToMillisecond");
|
4
|
-
describe('nanosecondToMillisecond', () => {
|
5
|
-
it.each `
|
6
|
-
input | expected
|
7
|
-
${'0.0001'} | ${0.0000000001}
|
8
|
-
${'1'} | ${0.000001}
|
9
|
-
${'1000000'} | ${1}
|
10
|
-
${'10000000'} | ${10}
|
11
|
-
${'-100000006'} | ${-100.000006}
|
12
|
-
${'1000000000000000000'} | ${1000000000000}
|
13
|
-
${'1234567891011100001'} | ${1234567891011.100001}
|
14
|
-
${'1234567891011100000'} | ${1234567891011.1}
|
15
|
-
${0.0001} | ${0.0000000001}
|
16
|
-
${1} | ${0.000001}
|
17
|
-
${1000000} | ${1}
|
18
|
-
${1000000000000001} | ${1000000000.000001}
|
19
|
-
`('should convert $input to $expected', ({ input, expected }) => {
|
20
|
-
expect((0, nanosecondToMillisecond_1.nanosecondToMillisecond)(input)).toBe(expected);
|
21
|
-
});
|
22
|
-
});
|
@@ -1,53 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const splitRobotTopic_1 = require("./splitRobotTopic");
|
4
|
-
describe('splitRobotTopic', () => {
|
5
|
-
it('should split a path with a single topic', () => {
|
6
|
-
expect((0, splitRobotTopic_1.splitRobotTopic)('/component/topic')).toEqual({
|
7
|
-
component: 'component',
|
8
|
-
topic: 'topic',
|
9
|
-
});
|
10
|
-
});
|
11
|
-
it('should split a path with multiple topics', () => {
|
12
|
-
expect((0, splitRobotTopic_1.splitRobotTopic)('/component/topic/with/multiple/topics')).toEqual({
|
13
|
-
component: 'component',
|
14
|
-
topic: 'topic/with/multiple/topics',
|
15
|
-
});
|
16
|
-
});
|
17
|
-
it('should split a path with no topics', () => {
|
18
|
-
expect((0, splitRobotTopic_1.splitRobotTopic)('/component')).toEqual({
|
19
|
-
component: 'component',
|
20
|
-
topic: '',
|
21
|
-
});
|
22
|
-
});
|
23
|
-
it('should split a path with no forward slash', () => {
|
24
|
-
expect((0, splitRobotTopic_1.splitRobotTopic)('component/topic')).toEqual({
|
25
|
-
component: 'component',
|
26
|
-
topic: 'topic',
|
27
|
-
});
|
28
|
-
});
|
29
|
-
it('should split a path with no forward slash and no topics', () => {
|
30
|
-
expect((0, splitRobotTopic_1.splitRobotTopic)('component')).toEqual({
|
31
|
-
component: 'component',
|
32
|
-
topic: '',
|
33
|
-
});
|
34
|
-
});
|
35
|
-
it('should split a path with no forward slash and multiple topics', () => {
|
36
|
-
expect((0, splitRobotTopic_1.splitRobotTopic)('component/topic/with/multiple/topics')).toEqual({
|
37
|
-
component: 'component',
|
38
|
-
topic: 'topic/with/multiple/topics',
|
39
|
-
});
|
40
|
-
});
|
41
|
-
it('should handle a path with multiple forward slashes', () => {
|
42
|
-
expect((0, splitRobotTopic_1.splitRobotTopic)('///component/topic/with/multiple/topics')).toEqual({
|
43
|
-
component: 'component',
|
44
|
-
topic: 'topic/with/multiple/topics',
|
45
|
-
});
|
46
|
-
});
|
47
|
-
it('should handle a path with multiple forward slashes and no topics', () => {
|
48
|
-
expect((0, splitRobotTopic_1.splitRobotTopic)('///component')).toEqual({
|
49
|
-
component: 'component',
|
50
|
-
topic: '',
|
51
|
-
});
|
52
|
-
});
|
53
|
-
});
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,13 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const standardDeviation_1 = require("./standardDeviation");
|
4
|
-
describe('standardDeviation', () => {
|
5
|
-
it('should calculate standard deviation correctly', () => {
|
6
|
-
let numbers = [10, 12, 23, 23, 16, 23, 21, 16];
|
7
|
-
let stdDev = (0, standardDeviation_1.standardDeviation)(numbers);
|
8
|
-
expect(Math.abs(stdDev - 4.8989794855664)).toBeLessThan(0.000001);
|
9
|
-
numbers = [100, 12, 23, 23, 116, 23, 21, 162];
|
10
|
-
stdDev = (0, standardDeviation_1.standardDeviation)(numbers);
|
11
|
-
expect(Math.abs(stdDev - 53.702886328394)).toBeLessThan(0.000001);
|
12
|
-
});
|
13
|
-
});
|
@@ -1,132 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
/**
|
3
|
-
* @jest-environment jsdom
|
4
|
-
*/
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
7
|
-
};
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
-
const manager_1 = __importDefault(require("./manager"));
|
10
|
-
const WorkerMocks = {
|
11
|
-
postMessage: jest.fn(),
|
12
|
-
terminate: jest.fn(),
|
13
|
-
addEventListener: jest.fn(),
|
14
|
-
removeEventListener: jest.fn(),
|
15
|
-
onerror: jest.fn(),
|
16
|
-
onmessage: jest.fn(),
|
17
|
-
onmessageerror: jest.fn(),
|
18
|
-
dispatchEvent: jest.fn(),
|
19
|
-
clearAllMocks() {
|
20
|
-
this.postMessage.mockClear();
|
21
|
-
this.terminate.mockClear();
|
22
|
-
this.addEventListener.mockClear();
|
23
|
-
this.removeEventListener.mockClear();
|
24
|
-
this.onerror.mockClear();
|
25
|
-
this.onmessage.mockClear();
|
26
|
-
this.onmessageerror.mockClear();
|
27
|
-
this.dispatchEvent.mockClear();
|
28
|
-
},
|
29
|
-
};
|
30
|
-
class MockWorkerClass {
|
31
|
-
constructor() {
|
32
|
-
this.postMessage = WorkerMocks.postMessage;
|
33
|
-
this.terminate = WorkerMocks.terminate;
|
34
|
-
this.addEventListener = WorkerMocks.addEventListener;
|
35
|
-
this.removeEventListener = WorkerMocks.removeEventListener;
|
36
|
-
this.onerror = WorkerMocks.onerror;
|
37
|
-
this.onmessage = WorkerMocks.onmessage;
|
38
|
-
this.onmessageerror = WorkerMocks.onmessageerror;
|
39
|
-
this.dispatchEvent = WorkerMocks.dispatchEvent;
|
40
|
-
}
|
41
|
-
}
|
42
|
-
Object.defineProperty(window, 'Worker', {
|
43
|
-
value: MockWorkerClass,
|
44
|
-
writable: true,
|
45
|
-
});
|
46
|
-
Object.defineProperty(window, 'URL', {
|
47
|
-
value: {
|
48
|
-
createObjectURL: jest.fn(),
|
49
|
-
},
|
50
|
-
});
|
51
|
-
// add mock to AbortSignal.timeout
|
52
|
-
Object.defineProperty(AbortSignal, 'timeout', {
|
53
|
-
value: jest.fn().mockImplementation((timeout) => {
|
54
|
-
return new AbortController().signal;
|
55
|
-
}),
|
56
|
-
});
|
57
|
-
const task = {
|
58
|
-
id: 'test',
|
59
|
-
code: '1',
|
60
|
-
timeout: 1000,
|
61
|
-
};
|
62
|
-
const response = {
|
63
|
-
data: {
|
64
|
-
id: 'test',
|
65
|
-
success: true,
|
66
|
-
result: 'test',
|
67
|
-
},
|
68
|
-
};
|
69
|
-
describe('WorkerManager', () => {
|
70
|
-
beforeEach(() => {
|
71
|
-
WorkerMocks.clearAllMocks();
|
72
|
-
});
|
73
|
-
it('should send a task to the worker', async () => {
|
74
|
-
const listeners = [];
|
75
|
-
WorkerMocks.addEventListener.mockImplementation((_, listener) => {
|
76
|
-
listeners.push(listener);
|
77
|
-
});
|
78
|
-
WorkerMocks.postMessage.mockImplementation((msg) => {
|
79
|
-
listeners.forEach((listener) => {
|
80
|
-
listener(response);
|
81
|
-
});
|
82
|
-
});
|
83
|
-
const manager = new manager_1.default();
|
84
|
-
const result = await manager.execute(task);
|
85
|
-
expect(result).toEqual('test');
|
86
|
-
});
|
87
|
-
it('should handle listener for a single task', async () => {
|
88
|
-
const listeners = [];
|
89
|
-
WorkerMocks.addEventListener.mockImplementation((_, listener) => {
|
90
|
-
listeners.push(listener);
|
91
|
-
});
|
92
|
-
WorkerMocks.removeEventListener.mockImplementation((_, listener) => {
|
93
|
-
const index = listeners.indexOf(listener);
|
94
|
-
listeners.splice(index, 1);
|
95
|
-
});
|
96
|
-
const manager = new manager_1.default();
|
97
|
-
expect(listeners.length).toEqual(0);
|
98
|
-
const result = manager.execute(task);
|
99
|
-
expect(listeners.length).toEqual(1);
|
100
|
-
listeners[0](response);
|
101
|
-
await result;
|
102
|
-
expect(listeners.length).toEqual(0);
|
103
|
-
});
|
104
|
-
it('should handle listener for multiple simultaneous task', async () => {
|
105
|
-
const listeners = [];
|
106
|
-
WorkerMocks.addEventListener.mockImplementation((_, listener) => {
|
107
|
-
listeners.push(listener);
|
108
|
-
});
|
109
|
-
WorkerMocks.removeEventListener.mockImplementation((_, listener) => {
|
110
|
-
const index = listeners.indexOf(listener);
|
111
|
-
listeners.splice(index, 1);
|
112
|
-
});
|
113
|
-
const manager = new manager_1.default();
|
114
|
-
expect(listeners.length).toEqual(0);
|
115
|
-
const result1 = manager.execute(task);
|
116
|
-
const result2 = manager.execute(task);
|
117
|
-
expect(listeners.length).toEqual(2);
|
118
|
-
const result3 = manager.execute(task);
|
119
|
-
expect(listeners.length).toEqual(3);
|
120
|
-
const [listener1, listener2, listener3] = listeners;
|
121
|
-
listener1(response);
|
122
|
-
await result1;
|
123
|
-
expect(listeners.length).toEqual(2);
|
124
|
-
listener3(response);
|
125
|
-
await result3;
|
126
|
-
expect(listeners.length).toEqual(1);
|
127
|
-
listener2(response);
|
128
|
-
await result2;
|
129
|
-
expect(listeners.length).toEqual(0);
|
130
|
-
expect(WorkerMocks.removeEventListener).toHaveBeenCalledTimes(3);
|
131
|
-
});
|
132
|
-
});
|
@@ -1,10 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.CallsignStatus = void 0;
|
4
|
-
var CallsignStatus;
|
5
|
-
(function (CallsignStatus) {
|
6
|
-
CallsignStatus["UNKNOWN"] = "unknown";
|
7
|
-
CallsignStatus["ONLINE"] = "online";
|
8
|
-
CallsignStatus["OFFLINE"] = "offline";
|
9
|
-
CallsignStatus["ERROR"] = "error";
|
10
|
-
})(CallsignStatus || (exports.CallsignStatus = CallsignStatus = {}));
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
package/cjs/models/Token.spec.js
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const Token_1 = require("./Token");
|
4
|
-
const generateToken = (config) => {
|
5
|
-
const defaultPayload = {
|
6
|
-
iat: 1234567890,
|
7
|
-
exp: 9876543210,
|
8
|
-
iss: 'myissuer',
|
9
|
-
aud: 'myaudience',
|
10
|
-
sub: 'mysubject',
|
11
|
-
};
|
12
|
-
const encodedHeader = Buffer.from(JSON.stringify(config?.header ?? { alg: 'HS256', typ: 'JWT' })).toString('base64');
|
13
|
-
const encodedPayload = Buffer.from(JSON.stringify(config?.payload ?? defaultPayload)).toString('base64');
|
14
|
-
if (config?.signature === null) {
|
15
|
-
return `${encodedHeader}.${encodedPayload}`;
|
16
|
-
}
|
17
|
-
return `${encodedHeader}.${encodedPayload}.${config?.signature ?? 'signature'}`;
|
18
|
-
};
|
19
|
-
describe('Token', () => {
|
20
|
-
describe('constructor', () => {
|
21
|
-
it('can get information from a valid token', () => {
|
22
|
-
const token = new Token_1.Token(generateToken());
|
23
|
-
expect(token.issuedAt).toEqual(new Date(1234567890000));
|
24
|
-
expect(token.expires).toEqual(new Date(9876543210000));
|
25
|
-
expect(token.issuer).toEqual('myissuer');
|
26
|
-
expect(token.audience).toEqual('myaudience');
|
27
|
-
expect(token.subject).toEqual('mysubject');
|
28
|
-
});
|
29
|
-
it('should throw an error for a non-jwt', () => {
|
30
|
-
// completely invalid string
|
31
|
-
expect(() => new Token_1.Token('not a jwt')).toThrowError('Invalid token');
|
32
|
-
// invalid header
|
33
|
-
expect(() => {
|
34
|
-
new Token_1.Token(generateToken({
|
35
|
-
header: {
|
36
|
-
alg: 'HS256',
|
37
|
-
typ: 'Not-a-JWT',
|
38
|
-
},
|
39
|
-
}));
|
40
|
-
}).toThrowError('Invalid token');
|
41
|
-
// too many parts
|
42
|
-
expect(() => {
|
43
|
-
new Token_1.Token('a.b.c.d');
|
44
|
-
}).toThrowError('Invalid token');
|
45
|
-
});
|
46
|
-
it('should allow a token with no signature', () => {
|
47
|
-
const token = new Token_1.Token(generateToken({ signature: null }));
|
48
|
-
expect(token.issuedAt).toEqual(new Date(1234567890000));
|
49
|
-
expect(token.expires).toEqual(new Date(9876543210000));
|
50
|
-
expect(token.issuer).toEqual('myissuer');
|
51
|
-
expect(token.audience).toEqual('myaudience');
|
52
|
-
expect(token.subject).toEqual('mysubject');
|
53
|
-
});
|
54
|
-
});
|
55
|
-
describe('isExpired', () => {
|
56
|
-
const baseDate = new Date(2021, 0, 1, 0, 0, 0, 0);
|
57
|
-
beforeEach(() => {
|
58
|
-
jest.useFakeTimers();
|
59
|
-
jest.setSystemTime(baseDate);
|
60
|
-
});
|
61
|
-
afterEach(() => {
|
62
|
-
jest.useRealTimers();
|
63
|
-
});
|
64
|
-
const expiredDate = (baseDate.getTime() - 1000 * 60 * 5) / 1000; // 5 minutes ago
|
65
|
-
const notExpiredDate = (baseDate.getTime() + 1000 * 60 * 60 * 24) / 1000; // 1 day from now
|
66
|
-
it('should return true if the token is expired', () => {
|
67
|
-
const token = new Token_1.Token(generateToken({ payload: { exp: expiredDate } }));
|
68
|
-
expect(token.isExpired()).toEqual(true);
|
69
|
-
});
|
70
|
-
it('should return false if the token is not expired', () => {
|
71
|
-
const token = new Token_1.Token(generateToken({ payload: { exp: notExpiredDate } }));
|
72
|
-
expect(token.isExpired()).toEqual(false);
|
73
|
-
});
|
74
|
-
});
|
75
|
-
describe('isExpiredIn', () => {
|
76
|
-
const baseDate = new Date(2021, 0, 1, 0, 0, 0, 0);
|
77
|
-
beforeEach(() => {
|
78
|
-
jest.useFakeTimers();
|
79
|
-
jest.setSystemTime(baseDate);
|
80
|
-
});
|
81
|
-
afterEach(() => {
|
82
|
-
jest.useRealTimers();
|
83
|
-
});
|
84
|
-
const expiredDate = (baseDate.getTime() - 1000 * 60 * 5) / 1000; // 5 minutes ago
|
85
|
-
const expiredIn5MinsDate = (baseDate.getTime() + 1000 * 60 * 5) / 1000; // 5 minutes from now
|
86
|
-
const expiredIn25MinsDate = (baseDate.getTime() + 1000 * 60 * 25) / 1000; // 25 minutes from now
|
87
|
-
const expiredIn2HoursDate = (baseDate.getTime() + 1000 * 60 * 60 * 2) / 1000; // 2 hours from now
|
88
|
-
it('should return true if the token is expired in the given time', () => {
|
89
|
-
const token = new Token_1.Token(generateToken({ payload: { exp: expiredIn5MinsDate } }));
|
90
|
-
expect(token.isExpiredIn(5, 'minutes')).toEqual(true);
|
91
|
-
expect(token.isExpiredIn(25, 'minutes')).toEqual(true);
|
92
|
-
expect(token.isExpiredIn(2, 'hours')).toEqual(true);
|
93
|
-
const token2 = new Token_1.Token(generateToken({ payload: { exp: expiredIn25MinsDate } }));
|
94
|
-
expect(token2.isExpiredIn(25, 'minutes')).toEqual(true);
|
95
|
-
expect(token2.isExpiredIn(2, 'hours')).toEqual(true);
|
96
|
-
const token3 = new Token_1.Token(generateToken({ payload: { exp: expiredDate } }));
|
97
|
-
expect(token3.isExpiredIn(5, 'minutes')).toEqual(true);
|
98
|
-
expect(token3.isExpiredIn(25, 'minutes')).toEqual(true);
|
99
|
-
expect(token3.isExpiredIn(2, 'hours')).toEqual(true);
|
100
|
-
});
|
101
|
-
it('should return false if the token is not expired in the given time', () => {
|
102
|
-
const token = new Token_1.Token(generateToken({ payload: { exp: expiredIn5MinsDate } }));
|
103
|
-
expect(token.isExpiredIn(4, 'minutes')).toEqual(false);
|
104
|
-
const token2 = new Token_1.Token(generateToken({ payload: { exp: expiredIn25MinsDate } }));
|
105
|
-
expect(token2.isExpiredIn(24, 'minutes')).toEqual(false);
|
106
|
-
const token3 = new Token_1.Token(generateToken({ payload: { exp: expiredIn2HoursDate } }));
|
107
|
-
expect(token3.isExpiredIn(1, 'hours')).toEqual(false);
|
108
|
-
});
|
109
|
-
});
|
110
|
-
});
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,165 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const auth_1 = require("../constants/auth");
|
4
|
-
const AuthService_1 = require("./AuthService");
|
5
|
-
const models_1 = require("../models");
|
6
|
-
describe('authService', () => {
|
7
|
-
const baseDate = new Date(2021, 0, 1, 0, 0, 0, 0);
|
8
|
-
beforeEach(() => {
|
9
|
-
jest.useFakeTimers();
|
10
|
-
jest.setSystemTime(baseDate);
|
11
|
-
});
|
12
|
-
const expiredDate = new Date(baseDate.getTime() - 1000 * 60 * 5); // 5 minutes ago
|
13
|
-
const almostExpiredDate = new Date(baseDate.getTime() + 1000 * 60 * 5); // 5 minutes from now
|
14
|
-
const almostAlmostExpiredDate = new Date(baseDate.getTime() + 1000 * 60 * 25); // 35 minutes from now
|
15
|
-
const notExpiredDate = new Date(baseDate.getTime() + 1000 * 60 * 60 * 24); // 1 day from now
|
16
|
-
const getToken = (config) => {
|
17
|
-
const header = {
|
18
|
-
alg: 'HS256',
|
19
|
-
typ: 'JWT',
|
20
|
-
};
|
21
|
-
const payload = {
|
22
|
-
iat: Math.floor((config.iat ?? expiredDate).getTime() / 1000),
|
23
|
-
exp: Math.floor((config.exp ?? notExpiredDate).getTime() / 1000),
|
24
|
-
iss: config.iss ?? auth_1.issuer,
|
25
|
-
aud: config.aud ?? 'myaudience',
|
26
|
-
sub: config.sub ?? 'mysubject',
|
27
|
-
};
|
28
|
-
const encodedHeader = Buffer.from(JSON.stringify(header)).toString('base64');
|
29
|
-
const encodedPayload = Buffer.from(JSON.stringify(payload)).toString('base64');
|
30
|
-
if (config.signature === false) {
|
31
|
-
return `${encodedHeader}.${encodedPayload}`;
|
32
|
-
}
|
33
|
-
return `${encodedHeader}.${encodedPayload}.signature`;
|
34
|
-
};
|
35
|
-
afterAll(() => jest.useRealTimers());
|
36
|
-
describe('getToken', () => {
|
37
|
-
it('should return the current token if it is not expired', async () => {
|
38
|
-
// Arrange
|
39
|
-
const token = getToken({ exp: notExpiredDate });
|
40
|
-
const service = new AuthService_1.AuthService({
|
41
|
-
token,
|
42
|
-
url: 'http://localhost:0',
|
43
|
-
});
|
44
|
-
service.setToken(token);
|
45
|
-
// Act
|
46
|
-
const newToken = await service.getToken();
|
47
|
-
// Assert
|
48
|
-
expect(newToken.value).toEqual(token);
|
49
|
-
});
|
50
|
-
it('should refresh the token if it is about to expire', async () => {
|
51
|
-
// Arrange
|
52
|
-
const token = getToken({ exp: almostExpiredDate });
|
53
|
-
const service = new AuthService_1.AuthService({
|
54
|
-
token,
|
55
|
-
url: 'http://localhost:0',
|
56
|
-
});
|
57
|
-
service.setToken(token);
|
58
|
-
const expected = getToken({ signature: false });
|
59
|
-
jest.spyOn(AuthService_1.AuthService.prototype, 'refreshToken').mockResolvedValue(new models_1.Token(expected));
|
60
|
-
// Act
|
61
|
-
const newToken = await service.getToken();
|
62
|
-
// Assert
|
63
|
-
expect(newToken.value).not.toEqual(token);
|
64
|
-
expect(newToken.value).toEqual(expected);
|
65
|
-
expect(AuthService_1.AuthService.prototype.refreshToken).toHaveBeenCalled();
|
66
|
-
});
|
67
|
-
it('should get a new token if there is no current token', async () => {
|
68
|
-
// Arrange
|
69
|
-
const token = getToken({ signature: false });
|
70
|
-
const service = new AuthService_1.AuthService({
|
71
|
-
url: 'http://localhost:0',
|
72
|
-
token,
|
73
|
-
});
|
74
|
-
service.clearToken();
|
75
|
-
const expected = getToken({ signature: false });
|
76
|
-
jest.spyOn(AuthService_1.AuthService.prototype, 'getNewUserToken').mockResolvedValue(new models_1.Token(expected));
|
77
|
-
// Act
|
78
|
-
const newToken = await service.getToken();
|
79
|
-
// Assert
|
80
|
-
expect(newToken.value).toEqual(expected);
|
81
|
-
expect(AuthService_1.AuthService.prototype.getNewUserToken).toHaveBeenCalled();
|
82
|
-
});
|
83
|
-
});
|
84
|
-
describe('tokenRefreshLoop', () => {
|
85
|
-
jest.spyOn(AuthService_1.AuthService.prototype, 'refreshTokenIfExpired').mockImplementation(() => {
|
86
|
-
// make sure the promise is resolved synchronously
|
87
|
-
return {
|
88
|
-
catch: () => {
|
89
|
-
return {
|
90
|
-
finally(onfinally) {
|
91
|
-
onfinally?.();
|
92
|
-
return Promise.resolve();
|
93
|
-
},
|
94
|
-
};
|
95
|
-
},
|
96
|
-
};
|
97
|
-
});
|
98
|
-
beforeEach(() => {
|
99
|
-
jest.clearAllTimers();
|
100
|
-
jest.clearAllMocks();
|
101
|
-
jest.useFakeTimers();
|
102
|
-
jest.setSystemTime(baseDate);
|
103
|
-
});
|
104
|
-
it('should check the token every 10 minutes', async () => {
|
105
|
-
// Arrange
|
106
|
-
const token = getToken({ exp: almostAlmostExpiredDate });
|
107
|
-
const service = new AuthService_1.AuthService({
|
108
|
-
token,
|
109
|
-
url: 'http://localhost:0',
|
110
|
-
});
|
111
|
-
service.setToken(token);
|
112
|
-
// Act
|
113
|
-
service.startTokenRefreshChecker();
|
114
|
-
expect(AuthService_1.AuthService.prototype.refreshTokenIfExpired).toHaveBeenCalledTimes(1);
|
115
|
-
jest.advanceTimersByTime(1000 * 60 * 10); // 10 minutes
|
116
|
-
expect(AuthService_1.AuthService.prototype.refreshTokenIfExpired).toHaveBeenCalledTimes(2);
|
117
|
-
jest.advanceTimersByTime(1000 * 60); // 1 minutes - 24 minutes left
|
118
|
-
expect(AuthService_1.AuthService.prototype.refreshTokenIfExpired).toHaveBeenCalledTimes(3);
|
119
|
-
jest.advanceTimersByTime(1000 * 60 * 10); // 10 minutes - 14 minutes left
|
120
|
-
jest.runOnlyPendingTimers(); // wait for the next timer to run
|
121
|
-
service.stopTokenRefreshChecker();
|
122
|
-
});
|
123
|
-
it('should not run again when cancelled', () => {
|
124
|
-
// Arrange
|
125
|
-
const token = getToken({ exp: notExpiredDate });
|
126
|
-
const service = new AuthService_1.AuthService({
|
127
|
-
token,
|
128
|
-
url: 'http://localhost:0',
|
129
|
-
});
|
130
|
-
service.setToken(token);
|
131
|
-
// Act
|
132
|
-
service.startTokenRefreshChecker();
|
133
|
-
expect(AuthService_1.AuthService.prototype.refreshTokenIfExpired).toHaveBeenCalledTimes(1);
|
134
|
-
service.stopTokenRefreshChecker();
|
135
|
-
jest.runOnlyPendingTimers();
|
136
|
-
expect(AuthService_1.AuthService.prototype.refreshTokenIfExpired).toHaveBeenCalledTimes(1);
|
137
|
-
});
|
138
|
-
it('should correctly report running status', () => {
|
139
|
-
const token = getToken({ exp: notExpiredDate });
|
140
|
-
const service = new AuthService_1.AuthService({
|
141
|
-
token,
|
142
|
-
url: 'http://localhost:0',
|
143
|
-
});
|
144
|
-
service.setToken(token);
|
145
|
-
expect(service.isTokenRefreshCheckerRunning()).toBe(false);
|
146
|
-
service.startTokenRefreshChecker();
|
147
|
-
expect(service.isTokenRefreshCheckerRunning()).toBe(true);
|
148
|
-
service.stopTokenRefreshChecker();
|
149
|
-
expect(service.isTokenRefreshCheckerRunning()).toBe(false);
|
150
|
-
});
|
151
|
-
it('should correctly report running status', () => {
|
152
|
-
const token = getToken({ exp: notExpiredDate });
|
153
|
-
const service = new AuthService_1.AuthService({
|
154
|
-
token,
|
155
|
-
url: 'http://localhost:0',
|
156
|
-
});
|
157
|
-
service.setToken(token);
|
158
|
-
expect(service.isTokenRefreshCheckerRunning()).toBe(false);
|
159
|
-
service.startTokenRefreshChecker();
|
160
|
-
expect(service.isTokenRefreshCheckerRunning()).toBe(true);
|
161
|
-
service.stopTokenRefreshChecker();
|
162
|
-
expect(service.isTokenRefreshCheckerRunning()).toBe(false);
|
163
|
-
});
|
164
|
-
});
|
165
|
-
});
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|