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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. package/cjs/IRocosSDK.d.ts +1 -2
  2. package/cjs/RocosSDK.d.ts +4 -6
  3. package/cjs/RocosSDK.js +1 -9
  4. package/cjs/api/streams/caller/CallerStream.js +5 -2
  5. package/cjs/api/streams/caller/CallerStreamNode.js +2 -1
  6. package/cjs/api/streams/command/CommandStream.js +5 -2
  7. package/cjs/api/streams/command/CommandStreamNode.js +2 -1
  8. package/cjs/api/streams/control/ControlStream.js +5 -2
  9. package/cjs/api/streams/control/ControlStreamAbstract.d.ts +1 -1
  10. package/cjs/api/streams/control/ControlStreamNode.js +2 -1
  11. package/cjs/api/streams/fileAccessor/FileAccessorStream.js +4 -1
  12. package/cjs/api/streams/fileAccessor/FileAccessorStreamNode.js +3 -1
  13. package/cjs/api/streams/search/SearchStream.js +5 -2
  14. package/cjs/api/streams/search/SearchStreamNode.js +2 -1
  15. package/cjs/api/streams/telemetry/TelemetryStream.js +4 -1
  16. package/cjs/api/streams/telemetry/TelemetryStreamAbstract.d.ts +1 -1
  17. package/cjs/api/streams/telemetry/TelemetryStreamNode.js +2 -1
  18. package/cjs/api/streams/webRTCSignalling/WebRTCSignallingStream.js +5 -2
  19. package/cjs/constants/api.d.ts +2 -4
  20. package/cjs/constants/api.js +4 -6
  21. package/cjs/helpers/getUniqueConfigKey.d.ts +6 -2
  22. package/cjs/helpers/getUniqueConfigKey.js +7 -2
  23. package/cjs/models/TelemetryStatus.d.ts +12 -0
  24. package/cjs/models/TelemetryStatus.js +17 -0
  25. package/cjs/models/Token.d.ts +2 -2
  26. package/cjs/models/Token.js +5 -5
  27. package/cjs/models/index.d.ts +1 -1
  28. package/cjs/models/index.js +1 -1
  29. package/cjs/node/RocosSDKNode.js +0 -3
  30. package/cjs/services/ProfileService.d.ts +23 -0
  31. package/cjs/services/ProfileService.js +28 -0
  32. package/cjs/services/RTPWebRTCService.d.ts +1 -1
  33. package/cjs/services/RTPWebRTCService.js +4 -2
  34. package/cjs/services/TelemetryService.d.ts +10 -1
  35. package/cjs/services/TelemetryService.js +27 -5
  36. package/cjs/services/index.d.ts +0 -1
  37. package/cjs/services/index.js +0 -1
  38. package/cjs/store/RocosStore.d.ts +1 -2
  39. package/esm/IRocosSDK.d.ts +1 -2
  40. package/esm/RocosSDK.d.ts +4 -6
  41. package/esm/RocosSDK.js +2 -10
  42. package/esm/api/streams/caller/CallerStream.js +5 -2
  43. package/esm/api/streams/caller/CallerStreamNode.js +2 -1
  44. package/esm/api/streams/command/CommandStream.js +5 -2
  45. package/esm/api/streams/command/CommandStreamNode.js +2 -1
  46. package/esm/api/streams/control/ControlStream.js +5 -2
  47. package/esm/api/streams/control/ControlStreamAbstract.d.ts +1 -1
  48. package/esm/api/streams/control/ControlStreamNode.js +2 -1
  49. package/esm/api/streams/fileAccessor/FileAccessorStream.js +4 -1
  50. package/esm/api/streams/fileAccessor/FileAccessorStreamNode.js +3 -1
  51. package/esm/api/streams/search/SearchStream.js +5 -2
  52. package/esm/api/streams/search/SearchStreamNode.js +2 -1
  53. package/esm/api/streams/telemetry/TelemetryStream.js +4 -1
  54. package/esm/api/streams/telemetry/TelemetryStreamAbstract.d.ts +1 -1
  55. package/esm/api/streams/telemetry/TelemetryStreamNode.js +2 -1
  56. package/esm/api/streams/webRTCSignalling/WebRTCSignallingStream.js +5 -2
  57. package/esm/constants/api.d.ts +2 -4
  58. package/esm/constants/api.js +2 -4
  59. package/esm/helpers/getUniqueConfigKey.d.ts +6 -2
  60. package/esm/helpers/getUniqueConfigKey.js +7 -2
  61. package/esm/models/TelemetryStatus.d.ts +12 -0
  62. package/esm/models/TelemetryStatus.js +14 -0
  63. package/esm/models/Token.d.ts +2 -2
  64. package/esm/models/Token.js +5 -5
  65. package/esm/models/index.d.ts +1 -1
  66. package/esm/models/index.js +1 -1
  67. package/esm/node/RocosSDKNode.js +1 -4
  68. package/esm/services/ProfileService.d.ts +23 -0
  69. package/esm/services/ProfileService.js +29 -1
  70. package/esm/services/RTPWebRTCService.d.ts +1 -1
  71. package/esm/services/RTPWebRTCService.js +4 -2
  72. package/esm/services/TelemetryService.d.ts +10 -1
  73. package/esm/services/TelemetryService.js +28 -6
  74. package/esm/services/index.d.ts +0 -1
  75. package/esm/services/index.js +0 -1
  76. package/esm/store/RocosStore.d.ts +1 -2
  77. package/package.json +1 -2
  78. package/cjs/helpers/cleanObject.spec.d.ts +0 -1
  79. package/cjs/helpers/cleanObject.spec.js +0 -55
  80. package/cjs/helpers/flattenObject.spec.d.ts +0 -1
  81. package/cjs/helpers/flattenObject.spec.js +0 -31
  82. package/cjs/helpers/flattenOneOf.spec.d.ts +0 -1
  83. package/cjs/helpers/flattenOneOf.spec.js +0 -159
  84. package/cjs/helpers/formatServiceUrl.spec.d.ts +0 -1
  85. package/cjs/helpers/formatServiceUrl.spec.js +0 -18
  86. package/cjs/helpers/getSha256Hex.spec.d.ts +0 -1
  87. package/cjs/helpers/getSha256Hex.spec.js +0 -19
  88. package/cjs/helpers/getSha256HexNode.spec.d.ts +0 -1
  89. package/cjs/helpers/getSha256HexNode.spec.js +0 -10
  90. package/cjs/helpers/getURLSearchParams.spec.d.ts +0 -1
  91. package/cjs/helpers/getURLSearchParams.spec.js +0 -21
  92. package/cjs/helpers/nanosecondToMillisecond.spec.d.ts +0 -1
  93. package/cjs/helpers/nanosecondToMillisecond.spec.js +0 -22
  94. package/cjs/helpers/splitRobotTopic.spec.d.ts +0 -1
  95. package/cjs/helpers/splitRobotTopic.spec.js +0 -53
  96. package/cjs/helpers/standardDeviation.spec.d.ts +0 -1
  97. package/cjs/helpers/standardDeviation.spec.js +0 -13
  98. package/cjs/helpers/websandbox/frame/worker/manager.spec.d.ts +0 -4
  99. package/cjs/helpers/websandbox/frame/worker/manager.spec.js +0 -132
  100. package/cjs/models/CallsignStatus.d.ts +0 -6
  101. package/cjs/models/CallsignStatus.js +0 -10
  102. package/cjs/models/Token.spec.d.ts +0 -1
  103. package/cjs/models/Token.spec.js +0 -110
  104. package/cjs/services/AuthService.spec.d.ts +0 -1
  105. package/cjs/services/AuthService.spec.js +0 -165
  106. package/cjs/services/CallerService.spec.d.ts +0 -1
  107. package/cjs/services/CallerService.spec.js +0 -229
  108. package/cjs/services/FunctionService.d.ts +0 -68
  109. package/cjs/services/FunctionService.js +0 -103
  110. package/cjs/services/PlatformTimeService.spec.d.ts +0 -1
  111. package/cjs/services/PlatformTimeService.spec.js +0 -182
  112. package/cjs/services/RTPWebRTCService.spec.d.ts +0 -4
  113. package/cjs/services/RTPWebRTCService.spec.js +0 -171
  114. package/cjs/services/TelemetryService.spec.d.ts +0 -1
  115. package/cjs/services/TelemetryService.spec.js +0 -39
  116. package/esm/helpers/cleanObject.spec.d.ts +0 -1
  117. package/esm/helpers/cleanObject.spec.js +0 -53
  118. package/esm/helpers/flattenObject.spec.d.ts +0 -1
  119. package/esm/helpers/flattenObject.spec.js +0 -29
  120. package/esm/helpers/flattenOneOf.spec.d.ts +0 -1
  121. package/esm/helpers/flattenOneOf.spec.js +0 -157
  122. package/esm/helpers/formatServiceUrl.spec.d.ts +0 -1
  123. package/esm/helpers/formatServiceUrl.spec.js +0 -16
  124. package/esm/helpers/getSha256Hex.spec.d.ts +0 -1
  125. package/esm/helpers/getSha256Hex.spec.js +0 -14
  126. package/esm/helpers/getSha256HexNode.spec.d.ts +0 -1
  127. package/esm/helpers/getSha256HexNode.spec.js +0 -8
  128. package/esm/helpers/getURLSearchParams.spec.d.ts +0 -1
  129. package/esm/helpers/getURLSearchParams.spec.js +0 -19
  130. package/esm/helpers/nanosecondToMillisecond.spec.d.ts +0 -1
  131. package/esm/helpers/nanosecondToMillisecond.spec.js +0 -20
  132. package/esm/helpers/splitRobotTopic.spec.d.ts +0 -1
  133. package/esm/helpers/splitRobotTopic.spec.js +0 -51
  134. package/esm/helpers/standardDeviation.spec.d.ts +0 -1
  135. package/esm/helpers/standardDeviation.spec.js +0 -11
  136. package/esm/helpers/websandbox/frame/worker/manager.spec.d.ts +0 -4
  137. package/esm/helpers/websandbox/frame/worker/manager.spec.js +0 -127
  138. package/esm/models/CallsignStatus.d.ts +0 -6
  139. package/esm/models/CallsignStatus.js +0 -7
  140. package/esm/models/Token.spec.d.ts +0 -1
  141. package/esm/models/Token.spec.js +0 -108
  142. package/esm/services/AuthService.spec.d.ts +0 -1
  143. package/esm/services/AuthService.spec.js +0 -163
  144. package/esm/services/CallerService.spec.d.ts +0 -1
  145. package/esm/services/CallerService.spec.js +0 -227
  146. package/esm/services/FunctionService.d.ts +0 -68
  147. package/esm/services/FunctionService.js +0 -99
  148. package/esm/services/PlatformTimeService.spec.d.ts +0 -1
  149. package/esm/services/PlatformTimeService.spec.js +0 -180
  150. package/esm/services/RTPWebRTCService.spec.d.ts +0 -4
  151. package/esm/services/RTPWebRTCService.spec.js +0 -169
  152. package/esm/services/TelemetryService.spec.d.ts +0 -1
  153. package/esm/services/TelemetryService.spec.js +0 -37
@@ -1,163 +0,0 @@
1
- import { issuer } from '../constants/auth';
2
- import { AuthService } from './AuthService';
3
- import { Token } from '../models';
4
- describe('authService', () => {
5
- const baseDate = new Date(2021, 0, 1, 0, 0, 0, 0);
6
- beforeEach(() => {
7
- jest.useFakeTimers();
8
- jest.setSystemTime(baseDate);
9
- });
10
- const expiredDate = new Date(baseDate.getTime() - 1000 * 60 * 5); // 5 minutes ago
11
- const almostExpiredDate = new Date(baseDate.getTime() + 1000 * 60 * 5); // 5 minutes from now
12
- const almostAlmostExpiredDate = new Date(baseDate.getTime() + 1000 * 60 * 25); // 35 minutes from now
13
- const notExpiredDate = new Date(baseDate.getTime() + 1000 * 60 * 60 * 24); // 1 day from now
14
- const getToken = (config) => {
15
- const header = {
16
- alg: 'HS256',
17
- typ: 'JWT',
18
- };
19
- const payload = {
20
- iat: Math.floor((config.iat ?? expiredDate).getTime() / 1000),
21
- exp: Math.floor((config.exp ?? notExpiredDate).getTime() / 1000),
22
- iss: config.iss ?? issuer,
23
- aud: config.aud ?? 'myaudience',
24
- sub: config.sub ?? 'mysubject',
25
- };
26
- const encodedHeader = Buffer.from(JSON.stringify(header)).toString('base64');
27
- const encodedPayload = Buffer.from(JSON.stringify(payload)).toString('base64');
28
- if (config.signature === false) {
29
- return `${encodedHeader}.${encodedPayload}`;
30
- }
31
- return `${encodedHeader}.${encodedPayload}.signature`;
32
- };
33
- afterAll(() => jest.useRealTimers());
34
- describe('getToken', () => {
35
- it('should return the current token if it is not expired', async () => {
36
- // Arrange
37
- const token = getToken({ exp: notExpiredDate });
38
- const service = new AuthService({
39
- token,
40
- url: 'http://localhost:0',
41
- });
42
- service.setToken(token);
43
- // Act
44
- const newToken = await service.getToken();
45
- // Assert
46
- expect(newToken.value).toEqual(token);
47
- });
48
- it('should refresh the token if it is about to expire', async () => {
49
- // Arrange
50
- const token = getToken({ exp: almostExpiredDate });
51
- const service = new AuthService({
52
- token,
53
- url: 'http://localhost:0',
54
- });
55
- service.setToken(token);
56
- const expected = getToken({ signature: false });
57
- jest.spyOn(AuthService.prototype, 'refreshToken').mockResolvedValue(new Token(expected));
58
- // Act
59
- const newToken = await service.getToken();
60
- // Assert
61
- expect(newToken.value).not.toEqual(token);
62
- expect(newToken.value).toEqual(expected);
63
- expect(AuthService.prototype.refreshToken).toHaveBeenCalled();
64
- });
65
- it('should get a new token if there is no current token', async () => {
66
- // Arrange
67
- const token = getToken({ signature: false });
68
- const service = new AuthService({
69
- url: 'http://localhost:0',
70
- token,
71
- });
72
- service.clearToken();
73
- const expected = getToken({ signature: false });
74
- jest.spyOn(AuthService.prototype, 'getNewUserToken').mockResolvedValue(new Token(expected));
75
- // Act
76
- const newToken = await service.getToken();
77
- // Assert
78
- expect(newToken.value).toEqual(expected);
79
- expect(AuthService.prototype.getNewUserToken).toHaveBeenCalled();
80
- });
81
- });
82
- describe('tokenRefreshLoop', () => {
83
- jest.spyOn(AuthService.prototype, 'refreshTokenIfExpired').mockImplementation(() => {
84
- // make sure the promise is resolved synchronously
85
- return {
86
- catch: () => {
87
- return {
88
- finally(onfinally) {
89
- onfinally?.();
90
- return Promise.resolve();
91
- },
92
- };
93
- },
94
- };
95
- });
96
- beforeEach(() => {
97
- jest.clearAllTimers();
98
- jest.clearAllMocks();
99
- jest.useFakeTimers();
100
- jest.setSystemTime(baseDate);
101
- });
102
- it('should check the token every 10 minutes', async () => {
103
- // Arrange
104
- const token = getToken({ exp: almostAlmostExpiredDate });
105
- const service = new AuthService({
106
- token,
107
- url: 'http://localhost:0',
108
- });
109
- service.setToken(token);
110
- // Act
111
- service.startTokenRefreshChecker();
112
- expect(AuthService.prototype.refreshTokenIfExpired).toHaveBeenCalledTimes(1);
113
- jest.advanceTimersByTime(1000 * 60 * 10); // 10 minutes
114
- expect(AuthService.prototype.refreshTokenIfExpired).toHaveBeenCalledTimes(2);
115
- jest.advanceTimersByTime(1000 * 60); // 1 minutes - 24 minutes left
116
- expect(AuthService.prototype.refreshTokenIfExpired).toHaveBeenCalledTimes(3);
117
- jest.advanceTimersByTime(1000 * 60 * 10); // 10 minutes - 14 minutes left
118
- jest.runOnlyPendingTimers(); // wait for the next timer to run
119
- service.stopTokenRefreshChecker();
120
- });
121
- it('should not run again when cancelled', () => {
122
- // Arrange
123
- const token = getToken({ exp: notExpiredDate });
124
- const service = new AuthService({
125
- token,
126
- url: 'http://localhost:0',
127
- });
128
- service.setToken(token);
129
- // Act
130
- service.startTokenRefreshChecker();
131
- expect(AuthService.prototype.refreshTokenIfExpired).toHaveBeenCalledTimes(1);
132
- service.stopTokenRefreshChecker();
133
- jest.runOnlyPendingTimers();
134
- expect(AuthService.prototype.refreshTokenIfExpired).toHaveBeenCalledTimes(1);
135
- });
136
- it('should correctly report running status', () => {
137
- const token = getToken({ exp: notExpiredDate });
138
- const service = new AuthService({
139
- token,
140
- url: 'http://localhost:0',
141
- });
142
- service.setToken(token);
143
- expect(service.isTokenRefreshCheckerRunning()).toBe(false);
144
- service.startTokenRefreshChecker();
145
- expect(service.isTokenRefreshCheckerRunning()).toBe(true);
146
- service.stopTokenRefreshChecker();
147
- expect(service.isTokenRefreshCheckerRunning()).toBe(false);
148
- });
149
- it('should correctly report running status', () => {
150
- const token = getToken({ exp: notExpiredDate });
151
- const service = new AuthService({
152
- token,
153
- url: 'http://localhost:0',
154
- });
155
- service.setToken(token);
156
- expect(service.isTokenRefreshCheckerRunning()).toBe(false);
157
- service.startTokenRefreshChecker();
158
- expect(service.isTokenRefreshCheckerRunning()).toBe(true);
159
- service.stopTokenRefreshChecker();
160
- expect(service.isTokenRefreshCheckerRunning()).toBe(false);
161
- });
162
- });
163
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,227 +0,0 @@
1
- import { AckStatus, ResultStatus, Stage, UIDVersion, } from '../models';
2
- import { concatMap, delay, from, of } from 'rxjs';
3
- import { CallerService } from './CallerService';
4
- import { TestScheduler } from 'rxjs/testing';
5
- const makeCallerMessage = (responses) => ({
6
- responses: {
7
- responses: responses ?? [],
8
- },
9
- });
10
- const makeCallerChunkedMessage = (responses) => {
11
- return responses.map((response, index) => {
12
- if ('return' in response) {
13
- throw new Error('Cannot create chunked message with return');
14
- }
15
- const chunk = response;
16
- chunk.chunkIndex = index;
17
- chunk.chunkCount = responses.length;
18
- chunk.header = {
19
- created: '0',
20
- meta: {},
21
- };
22
- return {
23
- chunks: {
24
- chunks: [chunk],
25
- },
26
- };
27
- });
28
- };
29
- const uid = {
30
- hash: 'hash',
31
- version: UIDVersion.HEADER_HASH_RAND,
32
- };
33
- const ack = (id) => ({
34
- uid,
35
- ack: {
36
- status: AckStatus.PROGRESS,
37
- message: id,
38
- stage: Stage.AGENT,
39
- },
40
- });
41
- const ret = (id) => {
42
- const encoder = new TextEncoder();
43
- const payload = encoder.encode(JSON.stringify({ id }));
44
- return {
45
- uid,
46
- return: {
47
- payload,
48
- },
49
- };
50
- };
51
- const chunkRet = (payload) => {
52
- const array = new TextEncoder().encode(payload);
53
- return {
54
- uid,
55
- payload: array,
56
- chunkIndex: 0,
57
- chunkCount: 1,
58
- header: {
59
- created: '0',
60
- meta: {},
61
- },
62
- };
63
- };
64
- const res = (ok) => ({
65
- uid,
66
- result: {
67
- status: ok ? ResultStatus.COMPLETE_SUCCESS : ResultStatus.FATAL,
68
- message: ok ? 'everything is fine' : 'nothing is fine',
69
- },
70
- });
71
- let testScheduler;
72
- let service;
73
- describe('CallerService', () => {
74
- beforeEach(() => {
75
- service = new CallerService({
76
- url: 'http://localhost:8080',
77
- token: 'token',
78
- });
79
- testScheduler = new TestScheduler((actual, expected) => {
80
- expect(actual).toEqual(expected);
81
- });
82
- });
83
- describe('callRaw', () => {
84
- it('should handle a successful call', () => {
85
- // Arrange
86
- jest.spyOn(service, 'invokeRequest').mockImplementation(() => {
87
- return from([
88
- makeCallerMessage([ack('a')]),
89
- makeCallerMessage([ack('b')]),
90
- makeCallerMessage([ack('c'), ret(1)]),
91
- makeCallerMessage([ret(2)]),
92
- makeCallerMessage([ret(3), ret(4)]),
93
- makeCallerMessage([ack('d')]),
94
- makeCallerMessage([ack('e')]),
95
- makeCallerMessage([ack('f')]),
96
- makeCallerMessage([ack('g'), res(true)]),
97
- makeCallerMessage([ack('h')]),
98
- ]).pipe(concatMap((item) => of(item).pipe(delay(1))));
99
- });
100
- testScheduler.run(({ expectObservable }) => {
101
- // Act
102
- const call = service.call({
103
- callsign: 'callsign',
104
- projectId: 'project',
105
- source: '/test',
106
- });
107
- // Assert
108
- const expectedAckMarbles = '-abc--def|';
109
- const expectedRetMarbles = '---ab(cd)|';
110
- const expectedResMarbles = '---------(a|)';
111
- const expectedAckValues = {
112
- a: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'a' },
113
- b: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'b' },
114
- c: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'c' },
115
- d: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'd' },
116
- e: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'e' },
117
- f: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'f' },
118
- };
119
- const expectedReturnValues = {
120
- a: { id: 1 },
121
- b: { id: 2 },
122
- c: { id: 3 },
123
- d: { id: 4 },
124
- };
125
- const expectedResultValues = {
126
- a: { status: ResultStatus.COMPLETE_SUCCESS, message: 'everything is fine' },
127
- };
128
- expectObservable(call.ack$).toBe(expectedAckMarbles, expectedAckValues);
129
- expectObservable(call.return$).toBe(expectedRetMarbles, expectedReturnValues);
130
- expectObservable(call.result$).toBe(expectedResMarbles, expectedResultValues);
131
- });
132
- });
133
- it('should handle a failed call', () => {
134
- // Arrange
135
- jest.spyOn(service, 'invokeRequest').mockImplementation(() => {
136
- return from([
137
- makeCallerMessage([ack('a')]),
138
- makeCallerMessage([ack('b')]),
139
- makeCallerMessage([ack('c'), ret(1)]),
140
- makeCallerMessage([ret(2)]),
141
- makeCallerMessage([ret(3), ret(4)]),
142
- makeCallerMessage([ack('d')]),
143
- makeCallerMessage([ack('e')]),
144
- makeCallerMessage([ack('f')]),
145
- makeCallerMessage([ack('g'), res(false)]),
146
- makeCallerMessage([ack('h')]),
147
- ]).pipe(concatMap((item) => of(item).pipe(delay(1))));
148
- });
149
- testScheduler.run(({ expectObservable }) => {
150
- // Act
151
- const call = service.call({
152
- callsign: 'callsign',
153
- projectId: 'project',
154
- source: '/test',
155
- });
156
- // Assert
157
- const expectedAckMarbles = '-abc--def#';
158
- const expectedRetMarbles = '---ab(cd)#';
159
- const expectedResMarbles = '---------(a|)';
160
- const expectedAckValues = {
161
- a: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'a' },
162
- b: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'b' },
163
- c: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'c' },
164
- d: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'd' },
165
- e: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'e' },
166
- f: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'f' },
167
- };
168
- const expectedReturnValues = {
169
- a: { id: 1 },
170
- b: { id: 2 },
171
- c: { id: 3 },
172
- d: { id: 4 },
173
- };
174
- const expectedResultValues = {
175
- a: { status: ResultStatus.FATAL, message: 'nothing is fine' },
176
- };
177
- expectObservable(call.ack$).toBe(expectedAckMarbles, expectedAckValues, res(false).result);
178
- expectObservable(call.return$).toBe(expectedRetMarbles, expectedReturnValues, res(false).result);
179
- expectObservable(call.result$).toBe(expectedResMarbles, expectedResultValues);
180
- });
181
- });
182
- it('should handle a successful chunked call', () => {
183
- // Arrange
184
- jest.spyOn(service, 'invokeRequest').mockImplementation(() => {
185
- return from([
186
- ...makeCallerChunkedMessage([
187
- chunkRet('[{"'),
188
- chunkRet('id":1},'),
189
- ack('a'),
190
- chunkRet('{"id":2}'),
191
- ack('b'),
192
- chunkRet(']'),
193
- ]),
194
- makeCallerMessage([ack('c'), ret(3)]),
195
- makeCallerMessage([res(true)]),
196
- ]).pipe(concatMap((item) => of(item).pipe(delay(1))));
197
- });
198
- testScheduler.run(({ expectObservable }) => {
199
- // Act
200
- const call = service.call({
201
- callsign: 'callsign',
202
- projectId: 'project',
203
- source: '/test',
204
- });
205
- // Assert
206
- const expectedAckMarbles = '---a-b-c|';
207
- const expectedRetMarbles = '------ab|';
208
- const expectedResMarbles = '--------(a|)';
209
- const expectedAckValues = {
210
- a: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'a' },
211
- b: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'b' },
212
- c: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'c' },
213
- };
214
- const expectedReturnValues = {
215
- a: [{ id: 1 }, { id: 2 }],
216
- b: { id: 3 },
217
- };
218
- const expectedResultValues = {
219
- a: { status: ResultStatus.COMPLETE_SUCCESS, message: 'everything is fine' },
220
- };
221
- expectObservable(call.ack$).toBe(expectedAckMarbles, expectedAckValues);
222
- expectObservable(call.return$).toBe(expectedRetMarbles, expectedReturnValues);
223
- expectObservable(call.result$).toBe(expectedResMarbles, expectedResultValues);
224
- });
225
- });
226
- });
227
- });
@@ -1,68 +0,0 @@
1
- import { RocosError } from '../models/RocosError';
2
- import { BaseServiceAbstract } from './BaseServiceAbstract';
3
- import { IBaseService } from '../models/IBaseService';
4
- import { IExportDataQuery } from '../models/IExportDataQuery';
5
- import { IFunctionConfig } from '../models/IFunctionConfig';
6
- import { IRocosSDKConfig } from '../models/IRocosSDKConfig';
7
- export declare class FunctionService extends BaseServiceAbstract implements IBaseService {
8
- constructor(config: IRocosSDKConfig);
9
- protected getError(e: Error): RocosError;
10
- getStatus(): boolean;
11
- /**
12
- * Export data
13
- *
14
- * @param projectId - Project Id
15
- * @param query - Payload {@link IExportDataQuery}
16
- */
17
- exportJobs(projectId: string, query: IExportDataQuery): Promise<any>;
18
- /**
19
- * Create a function
20
- *
21
- * @param projectId - Project Id
22
- * @param model - Payload {@link IFunctionConfig}
23
- */
24
- create(projectId: string, model: IFunctionConfig): Promise<any>;
25
- /**
26
- * Get a functions
27
- *
28
- * @param projectId - Project Id
29
- */
30
- list(projectId: string): Promise<any>;
31
- /**
32
- * Update a function
33
- *
34
- * @param projectId - Project Id
35
- * @param functionId - Function Id
36
- * @param model - Payload {@link IFunctionConfig}
37
- */
38
- update(projectId: string, functionId: string, model: IFunctionConfig): Promise<any>;
39
- /**
40
- * Get function
41
- *
42
- * @param projectId - Project Id
43
- * @param functionId - Function Id
44
- */
45
- info(projectId: string, functionId: string): Promise<any>;
46
- /**
47
- * Delete function
48
- *
49
- * @param projectId - Project Id
50
- * @param functionId - Function Id
51
- */
52
- delete(projectId: string, functionId: string): Promise<any>;
53
- /**
54
- * Run a function
55
- *
56
- * @param projectId - Project Id
57
- * @param functionId - Function Id
58
- * @param body - Payload
59
- */
60
- run(projectId: string, functionId: string, body?: any): Promise<any>;
61
- /**
62
- * Get function pods
63
- *
64
- * @param projectId - Project Id
65
- * @param functionId - Function Id
66
- */
67
- pods(projectId: string, functionId: string): Promise<any>;
68
- }
@@ -1,99 +0,0 @@
1
- import { API_PROJECT_EXPORT_URL, API_PROJECT_FUNCTION_ID_URL, API_PROJECT_FUNCTION_POD_URL, API_PROJECT_FUNCTION_RUN_URL, API_PROJECT_FUNCTION_URL, } from '../constants/api';
2
- import { RocosError, errorCodes } from '../models/RocosError';
3
- import { BaseServiceAbstract } from './BaseServiceAbstract';
4
- import { ExportDataQuery } from '../models/ExportDataQuery';
5
- import { RocosLogger } from '../logger/RocosLogger';
6
- import { formatServiceUrl } from '../helpers/formatServiceUrl';
7
- export class FunctionService extends BaseServiceAbstract {
8
- constructor(config) {
9
- super(config);
10
- this.logger = RocosLogger.getInstance(`FunctionService(${this.config.url})`);
11
- }
12
- getError(e) {
13
- return new RocosError(e, errorCodes.FUNCTION_SERVICE_ERROR);
14
- }
15
- getStatus() {
16
- return true;
17
- }
18
- /**
19
- * Export data
20
- *
21
- * @param projectId - Project Id
22
- * @param query - Payload {@link IExportDataQuery}
23
- */
24
- // TODO: map the response object
25
- async exportJobs(projectId, query) {
26
- return this.callPost(formatServiceUrl(API_PROJECT_EXPORT_URL, { url: this.config.url, projectId }, this.config.insecure), new ExportDataQuery(query).toJSON(), `Failed to export data for ${projectId}.`);
27
- }
28
- /**
29
- * Create a function
30
- *
31
- * @param projectId - Project Id
32
- * @param model - Payload {@link IFunctionConfig}
33
- */
34
- // TODO: map the response object
35
- async create(projectId, model) {
36
- return this.callPost(formatServiceUrl(API_PROJECT_FUNCTION_URL, { url: this.config.url, projectId }, this.config.insecure), model, `Failed to create function for ${projectId}.`);
37
- }
38
- /**
39
- * Get a functions
40
- *
41
- * @param projectId - Project Id
42
- */
43
- // TODO: map the response object
44
- async list(projectId) {
45
- return this.callGet(formatServiceUrl(API_PROJECT_FUNCTION_URL, { url: this.config.url, projectId }, this.config.insecure), `Failed to get functions for ${projectId}.`);
46
- }
47
- /**
48
- * Update a function
49
- *
50
- * @param projectId - Project Id
51
- * @param functionId - Function Id
52
- * @param model - Payload {@link IFunctionConfig}
53
- */
54
- // TODO: map the response object
55
- async update(projectId, functionId, model) {
56
- return this.callPut(formatServiceUrl(API_PROJECT_FUNCTION_ID_URL, { url: this.config.url, projectId, functionId }, this.config.insecure), model, `Failed to update function for ${projectId}, functionId ${functionId}.`);
57
- }
58
- /**
59
- * Get function
60
- *
61
- * @param projectId - Project Id
62
- * @param functionId - Function Id
63
- */
64
- // TODO: map the response object
65
- async info(projectId, functionId) {
66
- return this.callGet(formatServiceUrl(API_PROJECT_FUNCTION_ID_URL, { url: this.config.url, projectId, functionId }, this.config.insecure), `Failed to get function for ${projectId}, functionId ${functionId}.`);
67
- }
68
- /**
69
- * Delete function
70
- *
71
- * @param projectId - Project Id
72
- * @param functionId - Function Id
73
- */
74
- // TODO: map the response object
75
- async delete(projectId, functionId) {
76
- return this.callDelete(formatServiceUrl(API_PROJECT_FUNCTION_ID_URL, { url: this.config.url, projectId, functionId }, this.config.insecure), `Failed to delete function for ${projectId}, functionId ${functionId}.`);
77
- }
78
- /**
79
- * Run a function
80
- *
81
- * @param projectId - Project Id
82
- * @param functionId - Function Id
83
- * @param body - Payload
84
- */
85
- // TODO: map the response object
86
- async run(projectId, functionId, body = null) {
87
- return this.callPost(formatServiceUrl(API_PROJECT_FUNCTION_RUN_URL, { url: this.config.url, projectId, functionId }, this.config.insecure), body, `Failed to run function for ${projectId}, functionId ${functionId}.`);
88
- }
89
- /**
90
- * Get function pods
91
- *
92
- * @param projectId - Project Id
93
- * @param functionId - Function Id
94
- */
95
- // TODO: map the response object
96
- async pods(projectId, functionId) {
97
- return this.callGet(formatServiceUrl(API_PROJECT_FUNCTION_POD_URL, { url: this.config.url, projectId, functionId }, this.config.insecure), `Failed to ged function pods for ${projectId}, functionId ${functionId}.`);
98
- }
99
- }
@@ -1 +0,0 @@
1
- export {};