@forge/events 0.0.0-experimental-490cfcf → 0.0.0-experimental-51786e9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +156 -2
  2. package/out/__test__/invocationError.test.d.ts +2 -0
  3. package/out/__test__/invocationError.test.d.ts.map +1 -0
  4. package/out/__test__/invocationError.test.js +36 -0
  5. package/out/__test__/jobProgress.test.js +35 -26
  6. package/out/__test__/queue.test.js +46 -37
  7. package/out/__test__/utils.d.ts +1 -1
  8. package/out/__test__/utils.d.ts.map +1 -1
  9. package/out/__test__/utils.js +10 -6
  10. package/out/index.d.ts +3 -0
  11. package/out/index.d.ts.map +1 -1
  12. package/out/index.js +5 -0
  13. package/out/invocationError.d.ts +11 -0
  14. package/out/invocationError.d.ts.map +1 -0
  15. package/out/invocationError.js +22 -0
  16. package/out/invocationErrorCode.d.ts +9 -0
  17. package/out/invocationErrorCode.d.ts.map +1 -0
  18. package/out/invocationErrorCode.js +12 -0
  19. package/out/jobProgress.d.ts.map +1 -1
  20. package/out/jobProgress.js +8 -7
  21. package/out/queries.d.ts.map +1 -1
  22. package/out/queries.js +2 -1
  23. package/out/queue.d.ts.map +1 -1
  24. package/out/queue.js +8 -7
  25. package/out/queueResponse.d.ts +5 -1
  26. package/out/queueResponse.d.ts.map +1 -1
  27. package/out/queueResponse.js +9 -3
  28. package/out/retryOptions.d.ts +12 -0
  29. package/out/retryOptions.d.ts.map +1 -0
  30. package/out/retryOptions.js +9 -0
  31. package/out/validators.js +23 -14
  32. package/package.json +2 -2
  33. package/src/__test__/invocationError.test.ts +40 -0
  34. package/src/__test__/jobProgress.test.ts +31 -20
  35. package/src/__test__/queue.test.ts +40 -29
  36. package/src/__test__/utils.ts +1 -1
  37. package/src/index.ts +3 -0
  38. package/src/invocationError.ts +22 -0
  39. package/src/invocationErrorCode.ts +8 -0
  40. package/src/jobProgress.ts +2 -1
  41. package/src/queue.ts +2 -1
  42. package/src/queueResponse.ts +8 -2
  43. package/src/retryOptions.ts +14 -0
  44. package/tsconfig.tsbuildinfo +1 -1060
package/CHANGELOG.md CHANGED
@@ -1,10 +1,164 @@
1
1
  # @forge/events
2
2
 
3
- ## 0.0.0-experimental-490cfcf
3
+ ## 0.0.0-experimental-51786e9
4
+
5
+ ### Minor Changes
6
+
7
+ - dfab69c: Add NodeJS runtime support for Events API
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [dfab69c]
12
+ - @forge/api@0.0.0-experimental-51786e9
13
+
14
+ ## 0.8.0-next.0
15
+
16
+ ### Minor Changes
17
+
18
+ - dfab69c: Add NodeJS runtime support for Events API
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [dfab69c]
23
+ - @forge/api@2.10.1-next.0
24
+
25
+ ## 0.7.5
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [37f48c5]
30
+ - Updated dependencies [e0e3587]
31
+ - Updated dependencies [ca8551d]
32
+ - @forge/api@2.10.0
33
+
34
+ ## 0.7.5-next.1
35
+
36
+ ### Patch Changes
37
+
38
+ - Updated dependencies [e0e3587a]
39
+ - @forge/api@2.10.0-next.1
40
+
41
+ ## 0.7.5-next.0
42
+
43
+ ### Patch Changes
44
+
45
+ - Updated dependencies [ca8551dd]
46
+ - @forge/api@2.9.2-next.0
47
+
48
+ ## 0.7.4
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies [73b929a]
53
+ - Updated dependencies [8d0dc10]
54
+ - Updated dependencies [7a4fa35]
55
+ - @forge/api@2.9.1
56
+
57
+ ## 0.7.4-next.0
58
+
59
+ ### Patch Changes
60
+
61
+ - Updated dependencies [7a4fa35]
62
+ - @forge/api@2.9.1-next.0
63
+
64
+ ## 0.7.3
65
+
66
+ ### Patch Changes
67
+
68
+ - Updated dependencies [e5dd325]
69
+ - @forge/api@2.9.0
70
+
71
+ ## 0.7.3-next.0
72
+
73
+ ### Patch Changes
74
+
75
+ - Updated dependencies [e5dd325d]
76
+ - @forge/api@2.9.0-next.0
77
+
78
+ ## 0.7.2
79
+
80
+ ### Patch Changes
81
+
82
+ - Updated dependencies [8e2a5a6]
83
+ - @forge/api@2.8.1
84
+
85
+ ## 0.7.2-next.0
86
+
87
+ ### Patch Changes
88
+
89
+ - Updated dependencies [8e2a5a6]
90
+ - @forge/api@2.8.1-next.0
91
+
92
+ ## 0.7.1
93
+
94
+ ### Patch Changes
95
+
96
+ - Updated dependencies [95913f6]
97
+ - @forge/api@2.8.0
98
+
99
+ ## 0.7.1-next.0
100
+
101
+ ### Patch Changes
102
+
103
+ - Updated dependencies [95913f6]
104
+ - @forge/api@2.8.0-next.0
105
+
106
+ ## 0.7.0
107
+
108
+ ### Minor Changes
109
+
110
+ - e3af95e: Fix broken test for InvocationError
111
+ - d49508c: Fix broken test for InvocationError
112
+ - 6529a96: Add retryData into retryOptions
113
+ - 5062ab4: Fix broken test for InvocationError
114
+
115
+ ## 0.7.0-next.0
116
+
117
+ ### Minor Changes
118
+
119
+ - e3af95e: Fix broken test for InvocationError
120
+ - d49508c: Fix broken test for InvocationError
121
+ - 6529a96: Add retryData into retryOptions
122
+ - 5062ab4: Fix broken test for InvocationError
123
+
124
+ ## 0.6.1
125
+
126
+ ### Patch Changes
127
+
128
+ - 0e0a7b4: Returning object from InvocationError to make it transferrable.
129
+ - Updated dependencies [b3ee297]
130
+ - @forge/api@2.7.0
131
+
132
+ ## 0.6.1-next.1
133
+
134
+ ### Patch Changes
135
+
136
+ - Updated dependencies [b3ee2973]
137
+ - @forge/api@2.7.0-next.0
138
+
139
+ ## 0.6.1-next.0
140
+
141
+ ### Patch Changes
142
+
143
+ - 0e0a7b47: Returning object from InvocationError to make it transferrable.
144
+
145
+ ## 0.6.0
146
+
147
+ ### Minor Changes
148
+
149
+ - 0859c97: Allow app developers to return InvocationError on error from lambda function
150
+
151
+ ## 0.6.0-next.0
152
+
153
+ ### Minor Changes
154
+
155
+ - 0859c971: Allow app developers to return InvocationError on error from lambda function
156
+
157
+ ## 0.5.3
4
158
 
5
159
  ### Patch Changes
6
160
 
7
- - @forge/api@0.0.0-experimental-490cfcf
161
+ - @forge/api@2.6.1
8
162
 
9
163
  ## 0.5.3-next.0
10
164
 
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=invocationError.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invocationError.test.d.ts","sourceRoot":"","sources":["../../src/__test__/invocationError.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const invocationError_1 = require("../invocationError");
4
+ const invocationErrorCode_1 = require("../invocationErrorCode");
5
+ const retryOptions_1 = require("../retryOptions");
6
+ describe('InvocationError tests', () => {
7
+ let target = new invocationError_1.InvocationError();
8
+ it('Populate invocationError with default retryOptions and expect default retry option', async () => {
9
+ expect(target.retryOptions.retryAfter).toEqual(retryOptions_1.DEFAULT_RETRY_OPTIONS.retryAfter);
10
+ expect(target.retryOptions.retryReason).toEqual(invocationErrorCode_1.InvocationErrorCode.FUNCTION_RETRY_REQUEST);
11
+ expect(target.hasOwnProperty('_retry')).toBe(true);
12
+ });
13
+ it('Populate InvocationError with custom RetryOptions and expect the custom value to set.', () => {
14
+ const retryOptions = {
15
+ retryAfter: 10,
16
+ retryReason: invocationErrorCode_1.InvocationErrorCode.FUNCTION_OUT_OF_MEMORY,
17
+ retryData: {
18
+ eventsToSplit: 5
19
+ }
20
+ };
21
+ target = new invocationError_1.InvocationError(retryOptions);
22
+ expect(target.retryOptions).toEqual(retryOptions);
23
+ expect(target.hasOwnProperty('_retry')).toBe(true);
24
+ });
25
+ it('Use MIN_RETRY_AFTER when retryAfter <= 0', () => {
26
+ const retryOptions = {
27
+ retryAfter: 0,
28
+ retryReason: invocationErrorCode_1.InvocationErrorCode.FUNCTION_OUT_OF_MEMORY,
29
+ retryData: 'some string data'
30
+ };
31
+ target = new invocationError_1.InvocationError(retryOptions);
32
+ expect(target.retryOptions.retryAfter).toEqual(retryOptions_1.MIN_RETRY_AFTER);
33
+ expect(target.retryOptions.retryData).toEqual('some string data');
34
+ expect(target.hasOwnProperty('_retry')).toBe(true);
35
+ });
36
+ });
@@ -3,19 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const utils_1 = require("./utils");
4
4
  const errors_1 = require("../errors");
5
5
  const jobProgress_1 = require("../jobProgress");
6
- const getJobProgress = (apiClientMock, jobId) => new jobProgress_1.JobProgress(jobId, apiClientMock);
6
+ const api_1 = require("@forge/api");
7
+ jest.mock('@forge/api', () => ({
8
+ createRequestStargateAsApp: jest.fn().mockReturnValue((0, utils_1.getMockFetchMethod)('done', 200))
9
+ }));
10
+ const getJobProgress = (jobId, apiClientMock) => new jobProgress_1.JobProgress(jobId, apiClientMock);
7
11
  describe('JobProgress methods', () => {
8
12
  describe('getStats', () => {
9
13
  it('should call the queue/stats endpoint', async () => {
10
- const apiClientMock = utils_1.getApiClientMock({
14
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({
11
15
  success: 100,
12
16
  inProgress: 50,
13
17
  failed: 1
14
18
  }, 200);
15
- const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
19
+ const jobProgress = getJobProgress('test-queue-name#test-job-id', apiClientMock);
16
20
  const response = await jobProgress.getStats();
17
21
  const { success, inProgress, failed } = await response.json();
18
- utils_1.verifyApiClientCalledWith(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
22
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
19
23
  queueName: 'test-queue-name',
20
24
  jobId: 'test-job-id'
21
25
  });
@@ -24,35 +28,35 @@ describe('JobProgress methods', () => {
24
28
  expect(failed).toEqual(1);
25
29
  });
26
30
  it('should throw JobDoesNotExistError', async () => {
27
- const apiClientMock = utils_1.getApiClientMock({
31
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({
28
32
  message: 'Job Not Found',
29
33
  code: 404
30
34
  }, 404);
31
- const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
35
+ const jobProgress = getJobProgress('test-queue-name#test-job-id', apiClientMock);
32
36
  await expect(jobProgress.getStats()).rejects.toThrow(new errors_1.JobDoesNotExistError(`The job test-job-id was not found for the queue test-queue-name.`));
33
- utils_1.verifyApiClientCalledWith(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
37
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
34
38
  queueName: 'test-queue-name',
35
39
  jobId: 'test-job-id'
36
40
  });
37
41
  });
38
42
  it('should throw RateLimitError', async () => {
39
- const apiClientMock = utils_1.getApiClientMock({}, 429);
40
- const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
43
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({}, 429);
44
+ const jobProgress = getJobProgress('test-queue-name#test-job-id', apiClientMock);
41
45
  await expect(jobProgress.getStats()).rejects.toThrow(new errors_1.RateLimitError(`Too many requests.`));
42
- utils_1.verifyApiClientCalledWith(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
46
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
43
47
  queueName: 'test-queue-name',
44
48
  jobId: 'test-job-id'
45
49
  });
46
50
  });
47
51
  it('should throw InternalServerError', async () => {
48
- const apiClientMock = utils_1.getApiClientMock({
52
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({
49
53
  message: 'Service is not available',
50
54
  code: 513,
51
55
  details: 'The request processing has failed because of an unknown error, exception or failure'
52
56
  }, 513);
53
- const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
57
+ const jobProgress = getJobProgress('test-queue-name#test-job-id', apiClientMock);
54
58
  await expect(jobProgress.getStats()).rejects.toThrow(new errors_1.InternalServerError(`513 Status Text: Service is not available`, 513));
55
- utils_1.verifyApiClientCalledWith(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
59
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
56
60
  queueName: 'test-queue-name',
57
61
  jobId: 'test-job-id'
58
62
  });
@@ -60,51 +64,56 @@ describe('JobProgress methods', () => {
60
64
  });
61
65
  describe('cancel', () => {
62
66
  it('should call the queue/cancel endpoint', async () => {
63
- const apiClientMock = utils_1.getApiClientMock({}, 204);
64
- const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
67
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({}, 204);
68
+ const jobProgress = getJobProgress('test-queue-name#test-job-id', apiClientMock);
65
69
  const response = await jobProgress.cancel();
66
- utils_1.verifyApiClientCalledWith(apiClientMock, '/webhook/queue/cancel/{cloudId}/{environmentId}/{appId}/{appVersion}', {
70
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/cancel/{cloudId}/{environmentId}/{appId}/{appVersion}', {
67
71
  queueName: 'test-queue-name',
68
72
  jobId: 'test-job-id'
69
73
  });
70
74
  expect(response.status).toEqual(204);
71
75
  });
72
76
  it('should throw JobDoesNotExistError', async () => {
73
- const apiClientMock = utils_1.getApiClientMock({
77
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({
74
78
  message: 'Job Not Found',
75
79
  code: 404
76
80
  }, 404);
77
- const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
81
+ const jobProgress = getJobProgress('test-queue-name#test-job-id', apiClientMock);
78
82
  await expect(jobProgress.cancel()).rejects.toThrow(new errors_1.JobDoesNotExistError(`The job test-job-id was not found for the queue test-queue-name.`));
79
- utils_1.verifyApiClientCalledWith(apiClientMock, '/webhook/queue/cancel/{cloudId}/{environmentId}/{appId}/{appVersion}', {
83
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/cancel/{cloudId}/{environmentId}/{appId}/{appVersion}', {
80
84
  queueName: 'test-queue-name',
81
85
  jobId: 'test-job-id'
82
86
  });
83
87
  });
84
88
  });
85
89
  it('should throw InternalServerError when WHP returns 422 response', async () => {
86
- const apiClientMock = utils_1.getApiClientMock({
90
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({
87
91
  errors: ['jobId must not be null', 'queueName must not be null']
88
92
  }, 422);
89
- const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
93
+ const jobProgress = getJobProgress('test-queue-name#test-job-id', apiClientMock);
90
94
  await expect(jobProgress.getStats()).rejects.toThrow(new errors_1.InternalServerError(`422 Status Text: jobId must not be null, queueName must not be null`));
91
- utils_1.verifyApiClientCalledWith(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
95
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
92
96
  queueName: 'test-queue-name',
93
97
  jobId: 'test-job-id'
94
98
  });
95
99
  });
96
100
  it('should throw errors when queueName or jobId is empty', async () => {
97
- const apiClientMock = utils_1.getApiClientMock({
101
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({
98
102
  success: 100,
99
103
  inProgress: 50,
100
104
  failed: 1
101
105
  }, 200);
102
- const jobProgress1 = getJobProgress(apiClientMock, 'test-queue-name#');
106
+ const jobProgress1 = getJobProgress('test-queue-name#', apiClientMock);
103
107
  await expect(jobProgress1.getStats()).rejects.toThrow(new errors_1.JobDoesNotExistError(`jobId cannot be empty.`));
104
- const jobProgress2 = getJobProgress(apiClientMock, '#test-job-id');
108
+ const jobProgress2 = getJobProgress('#test-job-id', apiClientMock);
105
109
  await expect(jobProgress2.getStats()).rejects.toThrow(new errors_1.InvalidQueueNameError('Queue names can only contain alphanumeric characters, dashes and underscores.'));
106
- const jobProgress3 = getJobProgress(apiClientMock, '');
110
+ const jobProgress3 = getJobProgress('', apiClientMock);
107
111
  await expect(jobProgress3.getStats()).rejects.toThrow(new errors_1.JobDoesNotExistError(`jobId cannot be empty.`));
108
112
  expect(apiClientMock).toHaveBeenCalledTimes(0);
109
113
  });
114
+ it('requests stargate if no api client is provided', async () => {
115
+ const jobProgress = getJobProgress('test-queue-name#job-id');
116
+ await jobProgress.getStats();
117
+ expect((0, api_1.createRequestStargateAsApp)()).toBeCalledTimes(1);
118
+ });
110
119
  });
@@ -4,64 +4,68 @@ const errors_1 = require("../errors");
4
4
  const utils_1 = require("./utils");
5
5
  const queue_1 = require("../queue");
6
6
  const jobProgress_1 = require("../jobProgress");
7
- const getQueue = (apiClientMock, queueName) => new queue_1.Queue({ key: queueName }, apiClientMock);
7
+ const api_1 = require("@forge/api");
8
+ jest.mock('@forge/api', () => ({
9
+ createRequestStargateAsApp: jest.fn().mockReturnValue((0, utils_1.getMockFetchMethod)('done', 201))
10
+ }));
11
+ const getQueue = (queueName, apiClientMock) => new queue_1.Queue({ key: queueName }, apiClientMock);
8
12
  describe('Queue methods', () => {
9
13
  describe('constructor', () => {
10
14
  it('should throw InvalidQueueNameError', async () => {
11
- const apiClientMock = utils_1.getApiClientMock();
12
- expect(() => getQueue(apiClientMock, 'invalid name')).toThrowError(new errors_1.InvalidQueueNameError('Queue names can only contain alphanumeric characters, dashes and underscores.'));
15
+ const apiClientMock = (0, utils_1.getMockFetchMethod)();
16
+ expect(() => getQueue('invalid name', apiClientMock)).toThrowError(new errors_1.InvalidQueueNameError('Queue names can only contain alphanumeric characters, dashes and underscores.'));
13
17
  });
14
18
  });
15
19
  describe('push', () => {
16
20
  it('should call the queue/publish endpoint', async () => {
17
- const apiClientMock = utils_1.getApiClientMock();
18
- const queue = getQueue(apiClientMock, 'name');
21
+ const apiClientMock = (0, utils_1.getMockFetchMethod)();
22
+ const queue = getQueue('name', apiClientMock);
19
23
  const payload = {
20
24
  page: 1
21
25
  };
22
26
  await queue.push([payload]);
23
- utils_1.verifyApiClientCalledPushPathWith(apiClientMock, [payload], 'name');
27
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, [payload], 'name');
24
28
  });
25
29
  it('should throw InvalidPushSettingsError for delay', async () => {
26
- const apiClientMock = utils_1.getApiClientMock();
27
- const queue = getQueue(apiClientMock, 'name');
30
+ const apiClientMock = (0, utils_1.getMockFetchMethod)();
31
+ const queue = getQueue('name', apiClientMock);
28
32
  await expect(queue.push(1, { delayInSeconds: 901 })).rejects.toThrow(new errors_1.InvalidPushSettingsError(`The delayInSeconds setting must be between 0 and 900.`));
29
33
  expect(apiClientMock).toHaveBeenCalledTimes(0);
30
34
  });
31
35
  it('should throw NoEventsToPushError', async () => {
32
- const apiClientMock = utils_1.getApiClientMock();
33
- const queue = getQueue(apiClientMock, 'name');
36
+ const apiClientMock = (0, utils_1.getMockFetchMethod)();
37
+ const queue = getQueue('name', apiClientMock);
34
38
  await expect(queue.push([])).rejects.toThrow(new errors_1.NoEventsToPushError(`No events pushed.`));
35
39
  expect(apiClientMock).toHaveBeenCalledTimes(0);
36
40
  });
37
41
  it('should throw TooManyEventsError', async () => {
38
- const apiClientMock = utils_1.getApiClientMock();
39
- const queue = getQueue(apiClientMock, 'name');
42
+ const apiClientMock = (0, utils_1.getMockFetchMethod)();
43
+ const queue = getQueue('name', apiClientMock);
40
44
  await expect(queue.push([...Array(51).keys()])).rejects.toThrow(new errors_1.TooManyEventsError(`This push contains more than the 50 events allowed.`));
41
45
  expect(apiClientMock).toHaveBeenCalledTimes(0);
42
46
  });
43
47
  it('should throw PayloadTooBigError', async () => {
44
- const apiClientMock = utils_1.getApiClientMock();
45
- const queue = getQueue(apiClientMock, 'name');
48
+ const apiClientMock = (0, utils_1.getMockFetchMethod)();
49
+ const queue = getQueue('name', apiClientMock);
46
50
  await expect(queue.push('x'.repeat(201 * 1024))).rejects.toThrow(new errors_1.PayloadTooBigError(`The maximum payload size is 200KB.`));
47
51
  expect(apiClientMock).toHaveBeenCalledTimes(0);
48
52
  });
49
53
  it('should throw RateLimitError', async () => {
50
- const apiClientMock = utils_1.getApiClientMock({}, 429);
51
- const queue = getQueue(apiClientMock, 'name');
54
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({}, 429);
55
+ const queue = getQueue('name', apiClientMock);
52
56
  const payload = [...Array(10).keys()];
53
57
  await expect(queue.push(payload)).rejects.toThrow(new errors_1.RateLimitError(`Too many requests.`));
54
- utils_1.verifyApiClientCalledPushPathWith(apiClientMock, payload, 'name');
58
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
55
59
  });
56
60
  it('should throw InvocationLimitReachedError', async () => {
57
- const apiClientMock = utils_1.getApiClientMock({}, 405);
58
- const queue = getQueue(apiClientMock, 'name');
61
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({}, 405);
62
+ const queue = getQueue('name', apiClientMock);
59
63
  const payload = [...Array(5).keys()];
60
64
  await expect(queue.push(payload)).rejects.toThrow(new errors_1.InvocationLimitReachedError(`The limit on cyclic invocation has been reached.`));
61
- utils_1.verifyApiClientCalledPushPathWith(apiClientMock, payload, 'name');
65
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
62
66
  });
63
67
  it('should throw PartialSuccessError when there are failed events', async () => {
64
- const apiClientMock = utils_1.getApiClientMock({
68
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({
65
69
  failedEvents: [
66
70
  {
67
71
  index: '0',
@@ -73,7 +77,7 @@ describe('Queue methods', () => {
73
77
  }
74
78
  ]
75
79
  }, 202);
76
- const queue = getQueue(apiClientMock, 'name');
80
+ const queue = getQueue('name', apiClientMock);
77
81
  const payload = [
78
82
  {
79
83
  content: 'payload-1'
@@ -99,13 +103,13 @@ describe('Queue methods', () => {
99
103
  }
100
104
  }
101
105
  ]));
102
- utils_1.verifyApiClientCalledPushPathWith(apiClientMock, payload, 'name');
106
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
103
107
  });
104
108
  it('should throw PartialSuccessError when backend failed to create job stats', async () => {
105
- const apiClientMock = utils_1.getApiClientMock({
109
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({
106
110
  errorMessage: 'Failed to create stats for job name#12345'
107
111
  }, 202);
108
- const queue = getQueue(apiClientMock, 'name');
112
+ const queue = getQueue('name', apiClientMock);
109
113
  const payload = [
110
114
  {
111
115
  content: 'payload-1'
@@ -118,10 +122,10 @@ describe('Queue methods', () => {
118
122
  }
119
123
  ];
120
124
  await expect(queue.push(payload)).rejects.toThrow(new errors_1.PartialSuccessError(`Failed to create stats for job name#12345`, []));
121
- utils_1.verifyApiClientCalledPushPathWith(apiClientMock, payload, 'name');
125
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
122
126
  });
123
127
  it('should throw PartialSuccessError when there are failed events and backend failed to create job stats', async () => {
124
- const apiClientMock = utils_1.getApiClientMock({
128
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({
125
129
  errorMessage: 'Failed to create stats for job name#12345',
126
130
  failedEvents: [
127
131
  {
@@ -130,7 +134,7 @@ describe('Queue methods', () => {
130
134
  }
131
135
  ]
132
136
  }, 202);
133
- const queue = getQueue(apiClientMock, 'name');
137
+ const queue = getQueue('name', apiClientMock);
134
138
  const payload = [
135
139
  {
136
140
  content: 'payload-1'
@@ -147,31 +151,36 @@ describe('Queue methods', () => {
147
151
  }
148
152
  }
149
153
  ]));
150
- utils_1.verifyApiClientCalledPushPathWith(apiClientMock, payload, 'name');
154
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
151
155
  });
152
156
  it('should throw InternalServerError', async () => {
153
- const apiClientMock = utils_1.getApiClientMock({
157
+ const apiClientMock = (0, utils_1.getMockFetchMethod)({
154
158
  message: 'AWS SQS timed out',
155
159
  code: 500,
156
160
  details: 'The request processing has failed because of an unknown error, exception or failure'
157
161
  }, 500);
158
- const queue = getQueue(apiClientMock, 'name');
162
+ const queue = getQueue('name', apiClientMock);
159
163
  const payload = [...Array(9).keys()];
160
164
  await expect(queue.push(payload)).rejects.toThrow(new errors_1.InternalServerError(`500 Status Text: AWS SQS timed out`, 500, 'The request processing has failed because of an unknown error, exception or failure'));
161
- utils_1.verifyApiClientCalledPushPathWith(apiClientMock, payload, 'name');
165
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
162
166
  });
163
167
  it('should throw InternalServerError for error response without response body', async () => {
164
- const apiClientMock = utils_1.getApiClientMockWithoutResponseBody(504, 'Gateway Timeout');
165
- const queue = getQueue(apiClientMock, 'name');
168
+ const apiClientMock = (0, utils_1.getApiClientMockWithoutResponseBody)(504, 'Gateway Timeout');
169
+ const queue = getQueue('name', apiClientMock);
166
170
  const payload = [1];
167
171
  await expect(queue.push(1)).rejects.toThrow(new errors_1.InternalServerError(`504 Gateway Timeout`, 504));
168
- utils_1.verifyApiClientCalledPushPathWith(apiClientMock, payload, 'name');
172
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
173
+ });
174
+ it('requests stargate if no api client is provided', async () => {
175
+ const queue = getQueue('queue');
176
+ await queue.push({ test: 'stargate' });
177
+ expect((0, api_1.createRequestStargateAsApp)()).toBeCalledTimes(1);
169
178
  });
170
179
  });
171
180
  describe('getJob', () => {
172
181
  it('should create a JobProgress by jobId', async () => {
173
- const apiClientMock = utils_1.getApiClientMock();
174
- const queue = getQueue(apiClientMock, 'name');
182
+ const apiClientMock = (0, utils_1.getMockFetchMethod)();
183
+ const queue = getQueue('name', apiClientMock);
175
184
  const jobProgress = queue.getJob('test-job-id');
176
185
  expect(jobProgress).toEqual(new jobProgress_1.JobProgress('test-job-id', apiClientMock));
177
186
  });
@@ -1,6 +1,6 @@
1
1
  /// <reference types="jest" />
2
2
  import { Payload } from '../types';
3
- export declare const getApiClientMock: (response?: any, statusCode?: number) => jest.Mock<any, any>;
3
+ export declare const getMockFetchMethod: (response?: any, statusCode?: number) => jest.Mock<any, any>;
4
4
  export declare const getApiClientMockWithoutResponseBody: (statusCode: number, statusText: string) => jest.Mock<any, any>;
5
5
  export declare const verifyApiClientCalledWith: (apiClientMock: jest.Mock, path: string, expectedBody: any) => void;
6
6
  export declare const verifyApiClientCalledPushPathWith: (apiClientMock: jest.Mock, payloads: Payload | Payload[], name: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/__test__/utils.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,eAAO,MAAM,gBAAgB,cAAe,GAAG,6CAO9C,CAAC;AAEF,eAAO,MAAM,mCAAmC,eAAgB,MAAM,cAAc,MAAM,wBAMzF,CAAC;AAEF,eAAO,MAAM,yBAAyB,kBAAmB,IAAI,CAAC,IAAI,QAAQ,MAAM,gBAAgB,GAAG,SAclG,CAAC;AAEF,eAAO,MAAM,iCAAiC,kBAC7B,IAAI,CAAC,IAAI,YACd,OAAO,GAAG,OAAO,EAAE,QACvB,MAAM,SAQb,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/__test__/utils.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,eAAO,MAAM,kBAAkB,cAAe,GAAG,6CAOhD,CAAC;AAEF,eAAO,MAAM,mCAAmC,eAAgB,MAAM,cAAc,MAAM,wBAMzF,CAAC;AAEF,eAAO,MAAM,yBAAyB,kBAAmB,KAAK,IAAI,QAAQ,MAAM,gBAAgB,GAAG,SAclG,CAAC;AAEF,eAAO,MAAM,iCAAiC,kBAC7B,KAAK,IAAI,YACd,OAAO,GAAG,OAAO,EAAE,QACvB,MAAM,SAQb,CAAC"}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyApiClientCalledPushPathWith = exports.verifyApiClientCalledWith = exports.getApiClientMockWithoutResponseBody = exports.getApiClientMock = void 0;
4
- exports.getApiClientMock = (response, statusCode = 201) => {
3
+ exports.verifyApiClientCalledPushPathWith = exports.verifyApiClientCalledWith = exports.getApiClientMockWithoutResponseBody = exports.getMockFetchMethod = void 0;
4
+ const getMockFetchMethod = (response, statusCode = 201) => {
5
5
  return jest.fn().mockReturnValue({
6
6
  created: statusCode === 201,
7
7
  status: statusCode,
@@ -9,14 +9,16 @@ exports.getApiClientMock = (response, statusCode = 201) => {
9
9
  json: jest.fn().mockResolvedValue(response)
10
10
  });
11
11
  };
12
- exports.getApiClientMockWithoutResponseBody = (statusCode, statusText) => {
12
+ exports.getMockFetchMethod = getMockFetchMethod;
13
+ const getApiClientMockWithoutResponseBody = (statusCode, statusText) => {
13
14
  return jest.fn().mockReturnValue({
14
15
  ok: statusCode === 200,
15
16
  status: statusCode,
16
17
  statusText: statusText
17
18
  });
18
19
  };
19
- exports.verifyApiClientCalledWith = (apiClientMock, path, expectedBody) => {
20
+ exports.getApiClientMockWithoutResponseBody = getApiClientMockWithoutResponseBody;
21
+ const verifyApiClientCalledWith = (apiClientMock, path, expectedBody) => {
20
22
  expect(apiClientMock).toHaveBeenCalledWith(path, expect.objectContaining({
21
23
  method: 'POST',
22
24
  body: expect.any(String),
@@ -27,11 +29,13 @@ exports.verifyApiClientCalledWith = (apiClientMock, path, expectedBody) => {
27
29
  const [, { body }] = apiClientMock.mock.calls[0];
28
30
  expect(JSON.parse(body)).toEqual(expect.objectContaining(expectedBody));
29
31
  };
30
- exports.verifyApiClientCalledPushPathWith = (apiClientMock, payloads, name) => {
31
- exports.verifyApiClientCalledWith(apiClientMock, '/webhook/queue/publish/{cloudId}/{environmentId}/{appId}/{appVersion}', {
32
+ exports.verifyApiClientCalledWith = verifyApiClientCalledWith;
33
+ const verifyApiClientCalledPushPathWith = (apiClientMock, payloads, name) => {
34
+ (0, exports.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/publish/{cloudId}/{environmentId}/{appId}/{appVersion}', {
32
35
  queueName: name,
33
36
  schema: 'ari:cloud:ecosystem::forge/app-event',
34
37
  type: 'avi:forge:app:event',
35
38
  payload: payloads
36
39
  });
37
40
  };
41
+ exports.verifyApiClientCalledPushPathWith = verifyApiClientCalledPushPathWith;
package/out/index.d.ts CHANGED
@@ -2,4 +2,7 @@ export { Queue } from './queue';
2
2
  export { InvalidQueueNameError, TooManyEventsError, PayloadTooBigError, NoEventsToPushError, RateLimitError, PartialSuccessError, InternalServerError, JobDoesNotExistError, InvalidPushSettingsError, InvocationLimitReachedError } from './errors';
3
3
  export { JobProgress } from './jobProgress';
4
4
  export { QueueResponse } from './queueResponse';
5
+ export { InvocationError } from './invocationError';
6
+ export { InvocationErrorCode } from './invocationErrorCode';
7
+ export { RetryOptions } from './retryOptions';
5
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,2BAA2B,EAC5B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,2BAA2B,EAC5B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
package/out/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvocationErrorCode = exports.InvocationError = exports.QueueResponse = exports.JobProgress = exports.InvocationLimitReachedError = exports.InvalidPushSettingsError = exports.JobDoesNotExistError = exports.InternalServerError = exports.PartialSuccessError = exports.RateLimitError = exports.NoEventsToPushError = exports.PayloadTooBigError = exports.TooManyEventsError = exports.InvalidQueueNameError = exports.Queue = void 0;
3
4
  var queue_1 = require("./queue");
4
5
  Object.defineProperty(exports, "Queue", { enumerable: true, get: function () { return queue_1.Queue; } });
5
6
  var errors_1 = require("./errors");
@@ -17,3 +18,7 @@ var jobProgress_1 = require("./jobProgress");
17
18
  Object.defineProperty(exports, "JobProgress", { enumerable: true, get: function () { return jobProgress_1.JobProgress; } });
18
19
  var queueResponse_1 = require("./queueResponse");
19
20
  Object.defineProperty(exports, "QueueResponse", { enumerable: true, get: function () { return queueResponse_1.QueueResponse; } });
21
+ var invocationError_1 = require("./invocationError");
22
+ Object.defineProperty(exports, "InvocationError", { enumerable: true, get: function () { return invocationError_1.InvocationError; } });
23
+ var invocationErrorCode_1 = require("./invocationErrorCode");
24
+ Object.defineProperty(exports, "InvocationErrorCode", { enumerable: true, get: function () { return invocationErrorCode_1.InvocationErrorCode; } });
@@ -0,0 +1,11 @@
1
+ import { RetryOptions } from './retryOptions';
2
+ import { Response } from './queueResponse';
3
+ export declare class InvocationError extends Response {
4
+ retryOptions: RetryOptions;
5
+ constructor(retryOptions?: RetryOptions);
6
+ toJSON(): {
7
+ _retry: boolean;
8
+ retryOptions: RetryOptions;
9
+ };
10
+ }
11
+ //# sourceMappingURL=invocationError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invocationError.d.ts","sourceRoot":"","sources":["../src/invocationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0C,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,qBAAa,eAAgB,SAAQ,QAAQ;IACxB,YAAY,EAAE,YAAY;gBAA1B,YAAY,GAAE,YAAoC;IAW9D,MAAM,IAAI;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,YAAY,EAAE,YAAY,CAAA;KAAE;CAMjE"}