@dronedeploy/rocos-js-sdk 3.0.1-alpha.11 → 3.0.1-alpha.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. package/cjs/RocosSDK.d.ts +3 -1
  2. package/cjs/RocosSDK.js +1 -0
  3. package/cjs/api/streams/caller/CallerStream.js +5 -2
  4. package/cjs/api/streams/caller/CallerStreamNode.js +2 -1
  5. package/cjs/api/streams/command/CommandStream.js +5 -2
  6. package/cjs/api/streams/command/CommandStreamNode.js +2 -1
  7. package/cjs/api/streams/control/ControlStream.js +5 -2
  8. package/cjs/api/streams/control/ControlStreamAbstract.d.ts +1 -1
  9. package/cjs/api/streams/control/ControlStreamNode.js +2 -1
  10. package/cjs/api/streams/fileAccessor/FileAccessorStream.js +4 -1
  11. package/cjs/api/streams/fileAccessor/FileAccessorStreamNode.js +3 -1
  12. package/cjs/api/streams/search/SearchStream.js +5 -2
  13. package/cjs/api/streams/search/SearchStreamNode.js +2 -1
  14. package/cjs/api/streams/telemetry/TelemetryStream.js +4 -1
  15. package/cjs/api/streams/telemetry/TelemetryStreamAbstract.d.ts +1 -1
  16. package/cjs/api/streams/telemetry/TelemetryStreamNode.js +2 -1
  17. package/cjs/api/streams/webRTCSignalling/WebRTCSignallingStream.js +5 -2
  18. package/cjs/constants/api.d.ts +2 -0
  19. package/cjs/constants/api.js +4 -2
  20. package/cjs/helpers/getUniqueConfigKey.d.ts +6 -2
  21. package/cjs/helpers/getUniqueConfigKey.js +7 -2
  22. package/cjs/services/ProfileService.d.ts +23 -0
  23. package/cjs/services/ProfileService.js +28 -0
  24. package/cjs/services/RTPWebRTCService.d.ts +1 -1
  25. package/cjs/services/RTPWebRTCService.js +4 -2
  26. package/cjs/store/RocosStore.d.ts +1 -2
  27. package/esm/RocosSDK.d.ts +3 -1
  28. package/esm/RocosSDK.js +1 -0
  29. package/esm/api/streams/caller/CallerStream.js +5 -2
  30. package/esm/api/streams/caller/CallerStreamNode.js +2 -1
  31. package/esm/api/streams/command/CommandStream.js +5 -2
  32. package/esm/api/streams/command/CommandStreamNode.js +2 -1
  33. package/esm/api/streams/control/ControlStream.js +5 -2
  34. package/esm/api/streams/control/ControlStreamAbstract.d.ts +1 -1
  35. package/esm/api/streams/control/ControlStreamNode.js +2 -1
  36. package/esm/api/streams/fileAccessor/FileAccessorStream.js +4 -1
  37. package/esm/api/streams/fileAccessor/FileAccessorStreamNode.js +3 -1
  38. package/esm/api/streams/search/SearchStream.js +5 -2
  39. package/esm/api/streams/search/SearchStreamNode.js +2 -1
  40. package/esm/api/streams/telemetry/TelemetryStream.js +4 -1
  41. package/esm/api/streams/telemetry/TelemetryStreamAbstract.d.ts +1 -1
  42. package/esm/api/streams/telemetry/TelemetryStreamNode.js +2 -1
  43. package/esm/api/streams/webRTCSignalling/WebRTCSignallingStream.js +5 -2
  44. package/esm/constants/api.d.ts +2 -0
  45. package/esm/constants/api.js +2 -0
  46. package/esm/helpers/getUniqueConfigKey.d.ts +6 -2
  47. package/esm/helpers/getUniqueConfigKey.js +7 -2
  48. package/esm/services/ProfileService.d.ts +23 -0
  49. package/esm/services/ProfileService.js +29 -1
  50. package/esm/services/RTPWebRTCService.d.ts +1 -1
  51. package/esm/services/RTPWebRTCService.js +4 -2
  52. package/esm/store/RocosStore.d.ts +1 -2
  53. package/package.json +1 -1
  54. package/cjs/helpers/cleanObject.spec.d.ts +0 -1
  55. package/cjs/helpers/cleanObject.spec.js +0 -55
  56. package/cjs/helpers/flattenObject.spec.d.ts +0 -1
  57. package/cjs/helpers/flattenObject.spec.js +0 -31
  58. package/cjs/helpers/flattenOneOf.spec.d.ts +0 -1
  59. package/cjs/helpers/flattenOneOf.spec.js +0 -159
  60. package/cjs/helpers/formatServiceUrl.spec.d.ts +0 -1
  61. package/cjs/helpers/formatServiceUrl.spec.js +0 -18
  62. package/cjs/helpers/getSha256Hex.spec.d.ts +0 -1
  63. package/cjs/helpers/getSha256Hex.spec.js +0 -19
  64. package/cjs/helpers/getSha256HexNode.spec.d.ts +0 -1
  65. package/cjs/helpers/getSha256HexNode.spec.js +0 -10
  66. package/cjs/helpers/getURLSearchParams.spec.d.ts +0 -1
  67. package/cjs/helpers/getURLSearchParams.spec.js +0 -21
  68. package/cjs/helpers/nanosecondToMillisecond.spec.d.ts +0 -1
  69. package/cjs/helpers/nanosecondToMillisecond.spec.js +0 -22
  70. package/cjs/helpers/splitRobotTopic.spec.d.ts +0 -1
  71. package/cjs/helpers/splitRobotTopic.spec.js +0 -53
  72. package/cjs/helpers/standardDeviation.spec.d.ts +0 -1
  73. package/cjs/helpers/standardDeviation.spec.js +0 -13
  74. package/cjs/helpers/websandbox/frame/worker/manager.spec.d.ts +0 -4
  75. package/cjs/helpers/websandbox/frame/worker/manager.spec.js +0 -132
  76. package/cjs/models/Token.spec.d.ts +0 -1
  77. package/cjs/models/Token.spec.js +0 -110
  78. package/cjs/services/AuthService.spec.d.ts +0 -1
  79. package/cjs/services/AuthService.spec.js +0 -165
  80. package/cjs/services/CallerService.spec.d.ts +0 -1
  81. package/cjs/services/CallerService.spec.js +0 -229
  82. package/cjs/services/PlatformTimeService.spec.d.ts +0 -1
  83. package/cjs/services/PlatformTimeService.spec.js +0 -182
  84. package/cjs/services/RTPWebRTCService.spec.d.ts +0 -4
  85. package/cjs/services/RTPWebRTCService.spec.js +0 -171
  86. package/cjs/services/TelemetryService.spec.d.ts +0 -1
  87. package/cjs/services/TelemetryService.spec.js +0 -39
  88. package/esm/helpers/cleanObject.spec.d.ts +0 -1
  89. package/esm/helpers/cleanObject.spec.js +0 -53
  90. package/esm/helpers/flattenObject.spec.d.ts +0 -1
  91. package/esm/helpers/flattenObject.spec.js +0 -29
  92. package/esm/helpers/flattenOneOf.spec.d.ts +0 -1
  93. package/esm/helpers/flattenOneOf.spec.js +0 -157
  94. package/esm/helpers/formatServiceUrl.spec.d.ts +0 -1
  95. package/esm/helpers/formatServiceUrl.spec.js +0 -16
  96. package/esm/helpers/getSha256Hex.spec.d.ts +0 -1
  97. package/esm/helpers/getSha256Hex.spec.js +0 -14
  98. package/esm/helpers/getSha256HexNode.spec.d.ts +0 -1
  99. package/esm/helpers/getSha256HexNode.spec.js +0 -8
  100. package/esm/helpers/getURLSearchParams.spec.d.ts +0 -1
  101. package/esm/helpers/getURLSearchParams.spec.js +0 -19
  102. package/esm/helpers/nanosecondToMillisecond.spec.d.ts +0 -1
  103. package/esm/helpers/nanosecondToMillisecond.spec.js +0 -20
  104. package/esm/helpers/splitRobotTopic.spec.d.ts +0 -1
  105. package/esm/helpers/splitRobotTopic.spec.js +0 -51
  106. package/esm/helpers/standardDeviation.spec.d.ts +0 -1
  107. package/esm/helpers/standardDeviation.spec.js +0 -11
  108. package/esm/helpers/websandbox/frame/worker/manager.spec.d.ts +0 -4
  109. package/esm/helpers/websandbox/frame/worker/manager.spec.js +0 -127
  110. package/esm/models/Token.spec.d.ts +0 -1
  111. package/esm/models/Token.spec.js +0 -108
  112. package/esm/services/AuthService.spec.d.ts +0 -1
  113. package/esm/services/AuthService.spec.js +0 -163
  114. package/esm/services/CallerService.spec.d.ts +0 -1
  115. package/esm/services/CallerService.spec.js +0 -227
  116. package/esm/services/PlatformTimeService.spec.d.ts +0 -1
  117. package/esm/services/PlatformTimeService.spec.js +0 -180
  118. package/esm/services/RTPWebRTCService.spec.d.ts +0 -4
  119. package/esm/services/RTPWebRTCService.spec.js +0 -169
  120. package/esm/services/TelemetryService.spec.d.ts +0 -1
  121. package/esm/services/TelemetryService.spec.js +0 -37
@@ -77,9 +77,12 @@ export class WebRTCSignallingStream extends WebRTCSignallingStreamAbstract {
77
77
  return this.webRTCOperatorclient.addIceCandidate(request, { meta: metadata }).response;
78
78
  }
79
79
  getMetadata(projectId) {
80
- return {
81
- 'authorization': this.token,
80
+ const meta = {
82
81
  'r-p': projectId,
83
82
  };
83
+ if (this.token) {
84
+ meta.authorization = this.token;
85
+ }
86
+ return meta;
84
87
  }
85
88
  }
@@ -82,6 +82,8 @@ export declare const API_PROJECT_DEFINITION_ACTION_URL = "https://{url}/projects
82
82
  export declare const API_PROJECT_DEFINITION_BUTTON_URL = "https://{url}/projects/{projectId}/robot-definitions/{definitionId}/buttons";
83
83
  export declare const API_PROJECT_DEFINITION_TRIGGER_URL = "https://{url}/projects/{projectId}/robot-definitions/{definitionId}/triggers";
84
84
  export declare const API_PROJECT_DEFINITION_GAMEPAD_URL = "https://{url}/projects/{projectId}/robot-definitions/{definitionId}/gamepads";
85
+ export declare const API_PROJECT_DEFINITION_EXPORT = "https://{url}/projects/{projectId}/robot-definitions/{definitionId}/export";
86
+ export declare const API_PROJECT_DEFINITION_IMPORT = "https://{url}/projects/{projectId}/robot-definitions/import";
85
87
  export declare const API_PROJECT_GROUP_TYPE_URL = "https://{url}/projects/{projectId}/config-groups/{type}";
86
88
  export declare const API_PROJECT_GROUP_TYPE_ID_URL = "https://{url}/projects/{projectId}/config-groups/{type}/{configGroupId}";
87
89
  export declare const API_PROJECT_GROUP_TYPE_PUBLISH_URL = "https://{url}/projects/{projectId}/config-groups/{type}/{configGroupId}/publish";
@@ -82,6 +82,8 @@ export const API_PROJECT_DEFINITION_ACTION_URL = 'https://{url}/projects/{projec
82
82
  export const API_PROJECT_DEFINITION_BUTTON_URL = 'https://{url}/projects/{projectId}/robot-definitions/{definitionId}/buttons';
83
83
  export const API_PROJECT_DEFINITION_TRIGGER_URL = 'https://{url}/projects/{projectId}/robot-definitions/{definitionId}/triggers';
84
84
  export const API_PROJECT_DEFINITION_GAMEPAD_URL = 'https://{url}/projects/{projectId}/robot-definitions/{definitionId}/gamepads';
85
+ export const API_PROJECT_DEFINITION_EXPORT = 'https://{url}/projects/{projectId}/robot-definitions/{definitionId}/export';
86
+ export const API_PROJECT_DEFINITION_IMPORT = 'https://{url}/projects/{projectId}/robot-definitions/import';
85
87
  export const API_PROJECT_GROUP_TYPE_URL = 'https://{url}/projects/{projectId}/config-groups/{type}';
86
88
  export const API_PROJECT_GROUP_TYPE_ID_URL = 'https://{url}/projects/{projectId}/config-groups/{type}/{configGroupId}';
87
89
  export const API_PROJECT_GROUP_TYPE_PUBLISH_URL = 'https://{url}/projects/{projectId}/config-groups/{type}/{configGroupId}/publish';
@@ -1,7 +1,11 @@
1
- import { IRocosSDKConfig } from '../models/IRocosSDKConfig';
1
+ import { IRocosSDKConfig } from '../models';
2
+ type ConfigWithParent = IRocosSDKConfig & {
3
+ _parentConfig?: ConfigWithParent;
4
+ };
2
5
  /**
3
6
  * Flattens and orders the sdk config props to make a unique key
4
7
  *
5
8
  * @param config - SDK config {@link IRocosSDKConfig}
6
9
  */
7
- export declare const getUniqueConfigKey: (config: IRocosSDKConfig) => string;
10
+ export declare const getUniqueConfigKey: (config: ConfigWithParent) => string;
11
+ export {};
@@ -4,10 +4,15 @@
4
4
  * @param config - SDK config {@link IRocosSDKConfig}
5
5
  */
6
6
  export const getUniqueConfigKey = (config) => {
7
- return Object.keys(config)
7
+ let rootConfig = config;
8
+ if (rootConfig._parentConfig) {
9
+ // assume there is only one level of nesting
10
+ rootConfig = rootConfig._parentConfig;
11
+ }
12
+ return Object.keys(rootConfig)
8
13
  .sort()
9
14
  .map((item) => {
10
- return item !== 'token' ? `${item}:${config[item]}` : false;
15
+ return item !== 'token' ? `${item}:${rootConfig[item]}` : false;
11
16
  })
12
17
  .filter(Boolean)
13
18
  .join();
@@ -232,6 +232,29 @@ export declare class ProfileService extends BaseServiceAbstract implements IBase
232
232
  * @description - Renamed from robotDefGetGamepads
233
233
  */
234
234
  getGamepads(projectId: string, definitionId: string): Promise<any>;
235
+ /** Export robot definition into JSON format
236
+ *
237
+ * Can be used to import robot definition into another project
238
+ *
239
+ * @param projectId - Project Id
240
+ * @param definitionId - Robot definition Id
241
+ *
242
+ * @see import
243
+ */
244
+ export(projectId: string, definitionId: string): Promise<Record<string, unknown>>;
245
+ /** Import robot definition from JSON format
246
+ *
247
+ * Accepts a previously exported robot definition
248
+ *
249
+ * @param projectId - Project Id
250
+ * @param profileData - Robot definition data
251
+ * @param newName - Optional new name for the robot definition. If not provided, the name from the imported definition will be used.
252
+ *
253
+ * @see export
254
+ */
255
+ import(projectId: string, profileData: Record<string, unknown>, newName?: string): Promise<{
256
+ profileId: string;
257
+ }>;
235
258
  /**
236
259
  * Update gamepads for a robot definition
237
260
  *
@@ -1,4 +1,4 @@
1
- import { API_PROJECT_DEFINITION_ACTION_URL, API_PROJECT_DEFINITION_AGENT_URL, API_PROJECT_DEFINITION_BLOB_URL, API_PROJECT_DEFINITION_BUTTON_URL, API_PROJECT_DEFINITION_COMMAND2_URL, API_PROJECT_DEFINITION_COMMAND_URL, API_PROJECT_DEFINITION_COPY_URL, API_PROJECT_DEFINITION_DASHBOARD_URL, API_PROJECT_DEFINITION_GAMEPAD_URL, API_PROJECT_DEFINITION_ID_URL, API_PROJECT_DEFINITION_SETTING_URL, API_PROJECT_DEFINITION_STREAM_URL, API_PROJECT_DEFINITION_TRIGGER_URL, API_PROJECT_DEFINITION_URL, API_PROJECT_PROFILE_DASHBOARD_URL, API_PROJECT_ROBOT_DEFINITION_URL, API_PROJECT_ROBOT_URL, } from '../constants/api';
1
+ import { API_PROJECT_DEFINITION_ACTION_URL, API_PROJECT_DEFINITION_AGENT_URL, API_PROJECT_DEFINITION_BLOB_URL, API_PROJECT_DEFINITION_BUTTON_URL, API_PROJECT_DEFINITION_COMMAND2_URL, API_PROJECT_DEFINITION_COMMAND_URL, API_PROJECT_DEFINITION_COPY_URL, API_PROJECT_DEFINITION_DASHBOARD_URL, API_PROJECT_DEFINITION_EXPORT, API_PROJECT_DEFINITION_GAMEPAD_URL, API_PROJECT_DEFINITION_ID_URL, API_PROJECT_DEFINITION_IMPORT, API_PROJECT_DEFINITION_SETTING_URL, API_PROJECT_DEFINITION_STREAM_URL, API_PROJECT_DEFINITION_TRIGGER_URL, API_PROJECT_DEFINITION_URL, API_PROJECT_PROFILE_DASHBOARD_URL, API_PROJECT_ROBOT_DEFINITION_URL, API_PROJECT_ROBOT_URL, } from '../constants/api';
2
2
  import { RocosError, errorCodes } from '../models/RocosError';
3
3
  import { BaseServiceAbstract } from './BaseServiceAbstract';
4
4
  import { RocosLogger } from '../logger/RocosLogger';
@@ -345,6 +345,34 @@ export class ProfileService extends BaseServiceAbstract {
345
345
  async getGamepads(projectId, definitionId) {
346
346
  return this.callGet(formatServiceUrl(API_PROJECT_DEFINITION_GAMEPAD_URL, { url: this.config.url, projectId, definitionId }, this.config.insecure), `Failed to get gamepads for ${projectId}, definitionId ${definitionId}.`);
347
347
  }
348
+ /** Export robot definition into JSON format
349
+ *
350
+ * Can be used to import robot definition into another project
351
+ *
352
+ * @param projectId - Project Id
353
+ * @param definitionId - Robot definition Id
354
+ *
355
+ * @see import
356
+ */
357
+ async export(projectId, definitionId) {
358
+ return this.callPost(formatServiceUrl(API_PROJECT_DEFINITION_EXPORT, { url: this.config.url, projectId, definitionId }, this.config.insecure), undefined, `Failed to export robot definition for ${projectId}, definitionId ${definitionId}.`);
359
+ }
360
+ /** Import robot definition from JSON format
361
+ *
362
+ * Accepts a previously exported robot definition
363
+ *
364
+ * @param projectId - Project Id
365
+ * @param profileData - Robot definition data
366
+ * @param newName - Optional new name for the robot definition. If not provided, the name from the imported definition will be used.
367
+ *
368
+ * @see export
369
+ */
370
+ async import(projectId, profileData, newName) {
371
+ if (newName) {
372
+ profileData.name = newName;
373
+ }
374
+ return this.callPost(formatServiceUrl(API_PROJECT_DEFINITION_IMPORT, { url: this.config.url, projectId }, this.config.insecure), profileData, `Failed to import robot definition for ${projectId}.`);
375
+ }
348
376
  /**
349
377
  * Update gamepads for a robot definition
350
378
  *
@@ -54,7 +54,7 @@ export declare class RTPWebRTCService extends BaseServiceAbstract implements IBa
54
54
  *
55
55
  * If `logLevel` is set to trace, the connection will emit all messages as events
56
56
  */
57
- createPeerConnection(params: PeerConnectionParams): WebRTCConnection;
57
+ createPeerConnection(params: PeerConnectionParams): Promise<WebRTCConnection>;
58
58
  }
59
59
  export declare class WebRTCConnection {
60
60
  private pc?;
@@ -1,6 +1,7 @@
1
1
  import { RocosError, errorCodes } from '../models';
2
2
  import { Subject, scan, shareReplay } from 'rxjs';
3
3
  import { BaseServiceAbstract } from './BaseServiceAbstract';
4
+ import { RocosStore } from '../store/RocosStore';
4
5
  import { splitRobotTopic } from '../helpers/splitRobotTopic';
5
6
  export var WebRTCEventType;
6
7
  (function (WebRTCEventType) {
@@ -33,16 +34,17 @@ export class RTPWebRTCService extends BaseServiceAbstract {
33
34
  *
34
35
  * If `logLevel` is set to trace, the connection will emit all messages as events
35
36
  */
36
- createPeerConnection(params) {
37
+ async createPeerConnection(params) {
37
38
  const isInsecure = this.config.insecure ?? false;
38
39
  const port = this.config.port ?? (isInsecure ? 80 : 443);
40
+ const token = (await RocosStore.getSDKInstance(this.config).getAuthService().getToken()).value;
39
41
  return new WebRTCConnection({
40
42
  endpoint: {
41
43
  host: this.config.url,
42
44
  port,
43
45
  insecure: isInsecure,
44
46
  },
45
- token: this.config.token,
47
+ token,
46
48
  projectId: params.projectId,
47
49
  callsign: params.callsign,
48
50
  logLevel: params.logLevel,
@@ -1,6 +1,5 @@
1
- import { IRocosChangeMessage } from '../models/message/IRocosChangeMessage';
1
+ import { IRocosChangeMessage, IRocosSDKConfig } from '../models';
2
2
  import { IRocosSDK } from '../IRocosSDK';
3
- import { IRocosSDKConfig } from '../models/IRocosSDKConfig';
4
3
  import { Subject } from 'rxjs';
5
4
  export declare class RocosStore {
6
5
  private static changeSubject$?;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dronedeploy/rocos-js-sdk",
3
- "version": "3.0.1-alpha.11",
3
+ "version": "3.0.1-alpha.14",
4
4
  "description": "Javascript SDK for rocos",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -1 +0,0 @@
1
- export {};
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const cleanObject_1 = require("./cleanObject");
4
- describe('cleanObject', () => {
5
- const testObject = {
6
- test1: 'test1',
7
- test2: 'test2',
8
- test3: () => 'test3',
9
- test4: {
10
- test1: 'test1.1',
11
- test5: 'test5',
12
- test6: {
13
- test7: 'test7',
14
- test1: 'test1.2',
15
- test2: 'test2.1',
16
- test8: () => 'test8',
17
- },
18
- test8: () => 'test8',
19
- },
20
- test9: ['test9.1', 'test9.2', () => 'test8'],
21
- test10: [
22
- {
23
- test7: 'test7',
24
- test1: 'test1.2',
25
- test2: 'test2.1',
26
- test8: () => 'test8',
27
- },
28
- {
29
- test8: () => 'test8',
30
- },
31
- ],
32
- };
33
- it('should clean object to values only', () => {
34
- const newObject = (0, cleanObject_1.cleanObject)(testObject);
35
- expect(newObject?.test3).toBeUndefined();
36
- expect(newObject?.test4?.test8).toBeUndefined();
37
- expect(newObject?.test4?.test6?.test8).toBeUndefined();
38
- expect(newObject?.test4?.test5).toEqual('test5');
39
- expect(newObject?.test5).toBeUndefined();
40
- expect(newObject?.test4?.test6?.test1).toEqual('test1.2');
41
- expect(newObject?.test4?.test6?.test2).toEqual('test2.1');
42
- expect(newObject?.test1).toEqual('test1');
43
- expect(newObject?.test2).toEqual('test2');
44
- expect(newObject?.test9).toEqual(expect.arrayContaining(['test9.1', 'test9.2']));
45
- expect(newObject?.test9).toEqual(expect.not.arrayContaining([() => 'test8']));
46
- expect(newObject?.test10).toEqual(expect.arrayContaining([
47
- {
48
- test7: 'test7',
49
- test1: 'test1.2',
50
- test2: 'test2.1',
51
- },
52
- {},
53
- ]));
54
- });
55
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const flattenObject_1 = require("./flattenObject");
4
- describe('flattenObject', () => {
5
- const testObject = {
6
- test1: 'test1',
7
- test2: 'test2',
8
- test3: () => 'test3',
9
- test4: {
10
- test1: 'test1.1',
11
- test5: 'test5',
12
- test6: {
13
- test7: 'test7',
14
- test1: 'test1.2',
15
- test2: 'test2.1',
16
- test8: () => 'test8',
17
- },
18
- test8: () => 'test8',
19
- },
20
- };
21
- it('should flatten object to a single level', () => {
22
- const newObject = (0, flattenObject_1.flattenObject)(testObject);
23
- expect(newObject?.test3).toBeUndefined();
24
- expect(newObject?.test4?.test8).toBeUndefined();
25
- expect(newObject?.test4?.test6?.test8).toBeUndefined();
26
- expect(newObject?.test4?.test5).toBeUndefined();
27
- expect(newObject?.test5).toEqual('test5');
28
- expect(newObject?.test1).toEqual('test1.2');
29
- expect(newObject?.test2).toEqual('test2.1');
30
- });
31
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,159 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const flattenOneOf_1 = require("./flattenOneOf");
4
- describe('flattenOneOf', () => {
5
- describe('hasOneOfField', () => {
6
- it('should return false for non-object', () => {
7
- expect((0, flattenOneOf_1.hasOneOfField)(null)).toBe(false);
8
- expect((0, flattenOneOf_1.hasOneOfField)(undefined)).toBe(false);
9
- expect((0, flattenOneOf_1.hasOneOfField)(1)).toBe(false);
10
- expect((0, flattenOneOf_1.hasOneOfField)('')).toBe(false);
11
- expect((0, flattenOneOf_1.hasOneOfField)(true)).toBe(false);
12
- });
13
- it('should return false for null content', () => {
14
- expect((0, flattenOneOf_1.hasOneOfField)({ content: null })).toBe(false);
15
- });
16
- it('should return false for non-object content', () => {
17
- expect((0, flattenOneOf_1.hasOneOfField)({ content: 1 })).toBe(false);
18
- expect((0, flattenOneOf_1.hasOneOfField)({ content: '' })).toBe(false);
19
- expect((0, flattenOneOf_1.hasOneOfField)({ content: true })).toBe(false);
20
- });
21
- it('should return false for non-string oneofKind', () => {
22
- expect((0, flattenOneOf_1.hasOneOfField)({ content: { oneofKind: 1 } })).toBe(false);
23
- expect((0, flattenOneOf_1.hasOneOfField)({ content: { oneofKind: null } })).toBe(false);
24
- expect((0, flattenOneOf_1.hasOneOfField)({ content: { oneofKind: true } })).toBe(false);
25
- expect((0, flattenOneOf_1.hasOneOfField)({ content: { oneofKind: {} } })).toBe(false);
26
- });
27
- it('should return true for valid oneOfField', () => {
28
- expect((0, flattenOneOf_1.hasOneOfField)({ content: { oneofKind: 'test' } })).toBe(true);
29
- });
30
- });
31
- describe('flattenOneOf', () => {
32
- it('should flatten a simple oneof type', () => {
33
- const a = {
34
- a: 'a',
35
- content: {
36
- oneofKind: 'b',
37
- b: true,
38
- },
39
- };
40
- expect((0, flattenOneOf_1.flattenOneOf)(a)).toEqual({
41
- a: 'a',
42
- b: true,
43
- });
44
- });
45
- it('should flatten a nested oneof type, one level only', () => {
46
- const a = {
47
- b: {
48
- content: {
49
- oneofKind: 'c',
50
- c: true,
51
- },
52
- },
53
- content: {
54
- oneofKind: 'd',
55
- d: {
56
- content: {
57
- oneofKind: 'e',
58
- e: 5,
59
- },
60
- },
61
- },
62
- };
63
- expect((0, flattenOneOf_1.flattenOneOf)(a)).toEqual({
64
- b: {
65
- content: {
66
- oneofKind: 'c',
67
- c: true,
68
- },
69
- },
70
- d: {
71
- content: {
72
- oneofKind: 'e',
73
- e: 5,
74
- },
75
- },
76
- });
77
- });
78
- it('should flatten to undefined if the referenced property does not exist', () => {
79
- const a = {
80
- content: {
81
- oneofKind: 'b',
82
- c: true,
83
- },
84
- };
85
- expect((0, flattenOneOf_1.flattenOneOf)(a)).toEqual({
86
- b: undefined,
87
- });
88
- });
89
- it('should return the original object if it does not have a oneof field', () => {
90
- const a = {
91
- a: 'a',
92
- b: 'b',
93
- };
94
- expect((0, flattenOneOf_1.flattenOneOf)(a)).toEqual(a);
95
- });
96
- });
97
- describe('flattenOneOf - deep', () => {
98
- it('should flatten a simple oneof type', () => {
99
- const a = {
100
- a: 'a',
101
- content: {
102
- oneofKind: 'b',
103
- b: {
104
- d: 4,
105
- },
106
- },
107
- };
108
- expect((0, flattenOneOf_1.flattenOneOf)(a, true)).toEqual({
109
- a: 'a',
110
- b: { d: 4 },
111
- });
112
- });
113
- it('should flatten a nested oneof type, all levels', () => {
114
- const a = {
115
- b: {
116
- content: {
117
- oneofKind: 'c',
118
- c: true,
119
- },
120
- },
121
- content: {
122
- oneofKind: 'd',
123
- d: {
124
- content: {
125
- oneofKind: 'e',
126
- e: 5,
127
- },
128
- },
129
- },
130
- };
131
- expect((0, flattenOneOf_1.flattenOneOf)(a, true)).toEqual({
132
- b: {
133
- c: true,
134
- },
135
- d: {
136
- e: 5,
137
- },
138
- });
139
- });
140
- it('should flatten to undefined if the referenced property does not exist', () => {
141
- const a = {
142
- content: {
143
- oneofKind: 'b',
144
- c: true,
145
- },
146
- };
147
- expect((0, flattenOneOf_1.flattenOneOf)(a, true)).toEqual({
148
- b: undefined,
149
- });
150
- });
151
- it('should return the original object if it does not have a oneof field', () => {
152
- const a = {
153
- a: 'a',
154
- b: 'b',
155
- };
156
- expect((0, flattenOneOf_1.flattenOneOf)(a, true)).toEqual(a);
157
- });
158
- });
159
- });
@@ -1 +0,0 @@
1
- export {};
@@ -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 +0,0 @@
1
- export {};
@@ -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 +0,0 @@
1
- export {};
@@ -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 +0,0 @@
1
- export {};
@@ -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 +0,0 @@
1
- export {};
@@ -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 +0,0 @@
1
- export {};
@@ -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,4 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- export {};