@forge/events 0.7.0 → 0.7.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @forge/events
2
2
 
3
+ ## 0.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [95913f6]
8
+ - @forge/api@2.8.0
9
+
10
+ ## 0.7.1-next.0
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [95913f6]
15
+ - @forge/api@2.8.0-next.0
16
+
3
17
  ## 0.7.0
4
18
 
5
19
  ### Minor Changes
@@ -7,7 +7,7 @@ const getJobProgress = (apiClientMock, jobId) => new jobProgress_1.JobProgress(j
7
7
  describe('JobProgress methods', () => {
8
8
  describe('getStats', () => {
9
9
  it('should call the queue/stats endpoint', async () => {
10
- const apiClientMock = utils_1.getApiClientMock({
10
+ const apiClientMock = (0, utils_1.getApiClientMock)({
11
11
  success: 100,
12
12
  inProgress: 50,
13
13
  failed: 1
@@ -15,7 +15,7 @@ describe('JobProgress methods', () => {
15
15
  const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
16
16
  const response = await jobProgress.getStats();
17
17
  const { success, inProgress, failed } = await response.json();
18
- utils_1.verifyApiClientCalledWith(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
18
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
19
19
  queueName: 'test-queue-name',
20
20
  jobId: 'test-job-id'
21
21
  });
@@ -24,35 +24,35 @@ describe('JobProgress methods', () => {
24
24
  expect(failed).toEqual(1);
25
25
  });
26
26
  it('should throw JobDoesNotExistError', async () => {
27
- const apiClientMock = utils_1.getApiClientMock({
27
+ const apiClientMock = (0, utils_1.getApiClientMock)({
28
28
  message: 'Job Not Found',
29
29
  code: 404
30
30
  }, 404);
31
31
  const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
32
32
  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}', {
33
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
34
34
  queueName: 'test-queue-name',
35
35
  jobId: 'test-job-id'
36
36
  });
37
37
  });
38
38
  it('should throw RateLimitError', async () => {
39
- const apiClientMock = utils_1.getApiClientMock({}, 429);
39
+ const apiClientMock = (0, utils_1.getApiClientMock)({}, 429);
40
40
  const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
41
41
  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}', {
42
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
43
43
  queueName: 'test-queue-name',
44
44
  jobId: 'test-job-id'
45
45
  });
46
46
  });
47
47
  it('should throw InternalServerError', async () => {
48
- const apiClientMock = utils_1.getApiClientMock({
48
+ const apiClientMock = (0, utils_1.getApiClientMock)({
49
49
  message: 'Service is not available',
50
50
  code: 513,
51
51
  details: 'The request processing has failed because of an unknown error, exception or failure'
52
52
  }, 513);
53
53
  const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
54
54
  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}', {
55
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
56
56
  queueName: 'test-queue-name',
57
57
  jobId: 'test-job-id'
58
58
  });
@@ -60,41 +60,41 @@ describe('JobProgress methods', () => {
60
60
  });
61
61
  describe('cancel', () => {
62
62
  it('should call the queue/cancel endpoint', async () => {
63
- const apiClientMock = utils_1.getApiClientMock({}, 204);
63
+ const apiClientMock = (0, utils_1.getApiClientMock)({}, 204);
64
64
  const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
65
65
  const response = await jobProgress.cancel();
66
- utils_1.verifyApiClientCalledWith(apiClientMock, '/webhook/queue/cancel/{cloudId}/{environmentId}/{appId}/{appVersion}', {
66
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/cancel/{cloudId}/{environmentId}/{appId}/{appVersion}', {
67
67
  queueName: 'test-queue-name',
68
68
  jobId: 'test-job-id'
69
69
  });
70
70
  expect(response.status).toEqual(204);
71
71
  });
72
72
  it('should throw JobDoesNotExistError', async () => {
73
- const apiClientMock = utils_1.getApiClientMock({
73
+ const apiClientMock = (0, utils_1.getApiClientMock)({
74
74
  message: 'Job Not Found',
75
75
  code: 404
76
76
  }, 404);
77
77
  const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
78
78
  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}', {
79
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/cancel/{cloudId}/{environmentId}/{appId}/{appVersion}', {
80
80
  queueName: 'test-queue-name',
81
81
  jobId: 'test-job-id'
82
82
  });
83
83
  });
84
84
  });
85
85
  it('should throw InternalServerError when WHP returns 422 response', async () => {
86
- const apiClientMock = utils_1.getApiClientMock({
86
+ const apiClientMock = (0, utils_1.getApiClientMock)({
87
87
  errors: ['jobId must not be null', 'queueName must not be null']
88
88
  }, 422);
89
89
  const jobProgress = getJobProgress(apiClientMock, 'test-queue-name#test-job-id');
90
90
  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}', {
91
+ (0, utils_1.verifyApiClientCalledWith)(apiClientMock, '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}', {
92
92
  queueName: 'test-queue-name',
93
93
  jobId: 'test-job-id'
94
94
  });
95
95
  });
96
96
  it('should throw errors when queueName or jobId is empty', async () => {
97
- const apiClientMock = utils_1.getApiClientMock({
97
+ const apiClientMock = (0, utils_1.getApiClientMock)({
98
98
  success: 100,
99
99
  inProgress: 50,
100
100
  failed: 1
@@ -8,60 +8,60 @@ const getQueue = (apiClientMock, queueName) => new queue_1.Queue({ key: queueNam
8
8
  describe('Queue methods', () => {
9
9
  describe('constructor', () => {
10
10
  it('should throw InvalidQueueNameError', async () => {
11
- const apiClientMock = utils_1.getApiClientMock();
11
+ const apiClientMock = (0, utils_1.getApiClientMock)();
12
12
  expect(() => getQueue(apiClientMock, 'invalid name')).toThrowError(new errors_1.InvalidQueueNameError('Queue names can only contain alphanumeric characters, dashes and underscores.'));
13
13
  });
14
14
  });
15
15
  describe('push', () => {
16
16
  it('should call the queue/publish endpoint', async () => {
17
- const apiClientMock = utils_1.getApiClientMock();
17
+ const apiClientMock = (0, utils_1.getApiClientMock)();
18
18
  const queue = getQueue(apiClientMock, 'name');
19
19
  const payload = {
20
20
  page: 1
21
21
  };
22
22
  await queue.push([payload]);
23
- utils_1.verifyApiClientCalledPushPathWith(apiClientMock, [payload], 'name');
23
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, [payload], 'name');
24
24
  });
25
25
  it('should throw InvalidPushSettingsError for delay', async () => {
26
- const apiClientMock = utils_1.getApiClientMock();
26
+ const apiClientMock = (0, utils_1.getApiClientMock)();
27
27
  const queue = getQueue(apiClientMock, 'name');
28
28
  await expect(queue.push(1, { delayInSeconds: 901 })).rejects.toThrow(new errors_1.InvalidPushSettingsError(`The delayInSeconds setting must be between 0 and 900.`));
29
29
  expect(apiClientMock).toHaveBeenCalledTimes(0);
30
30
  });
31
31
  it('should throw NoEventsToPushError', async () => {
32
- const apiClientMock = utils_1.getApiClientMock();
32
+ const apiClientMock = (0, utils_1.getApiClientMock)();
33
33
  const queue = getQueue(apiClientMock, 'name');
34
34
  await expect(queue.push([])).rejects.toThrow(new errors_1.NoEventsToPushError(`No events pushed.`));
35
35
  expect(apiClientMock).toHaveBeenCalledTimes(0);
36
36
  });
37
37
  it('should throw TooManyEventsError', async () => {
38
- const apiClientMock = utils_1.getApiClientMock();
38
+ const apiClientMock = (0, utils_1.getApiClientMock)();
39
39
  const queue = getQueue(apiClientMock, 'name');
40
40
  await expect(queue.push([...Array(51).keys()])).rejects.toThrow(new errors_1.TooManyEventsError(`This push contains more than the 50 events allowed.`));
41
41
  expect(apiClientMock).toHaveBeenCalledTimes(0);
42
42
  });
43
43
  it('should throw PayloadTooBigError', async () => {
44
- const apiClientMock = utils_1.getApiClientMock();
44
+ const apiClientMock = (0, utils_1.getApiClientMock)();
45
45
  const queue = getQueue(apiClientMock, 'name');
46
46
  await expect(queue.push('x'.repeat(201 * 1024))).rejects.toThrow(new errors_1.PayloadTooBigError(`The maximum payload size is 200KB.`));
47
47
  expect(apiClientMock).toHaveBeenCalledTimes(0);
48
48
  });
49
49
  it('should throw RateLimitError', async () => {
50
- const apiClientMock = utils_1.getApiClientMock({}, 429);
50
+ const apiClientMock = (0, utils_1.getApiClientMock)({}, 429);
51
51
  const queue = getQueue(apiClientMock, 'name');
52
52
  const payload = [...Array(10).keys()];
53
53
  await expect(queue.push(payload)).rejects.toThrow(new errors_1.RateLimitError(`Too many requests.`));
54
- utils_1.verifyApiClientCalledPushPathWith(apiClientMock, payload, 'name');
54
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
55
55
  });
56
56
  it('should throw InvocationLimitReachedError', async () => {
57
- const apiClientMock = utils_1.getApiClientMock({}, 405);
57
+ const apiClientMock = (0, utils_1.getApiClientMock)({}, 405);
58
58
  const queue = getQueue(apiClientMock, 'name');
59
59
  const payload = [...Array(5).keys()];
60
60
  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');
61
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
62
62
  });
63
63
  it('should throw PartialSuccessError when there are failed events', async () => {
64
- const apiClientMock = utils_1.getApiClientMock({
64
+ const apiClientMock = (0, utils_1.getApiClientMock)({
65
65
  failedEvents: [
66
66
  {
67
67
  index: '0',
@@ -99,10 +99,10 @@ describe('Queue methods', () => {
99
99
  }
100
100
  }
101
101
  ]));
102
- utils_1.verifyApiClientCalledPushPathWith(apiClientMock, payload, 'name');
102
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
103
103
  });
104
104
  it('should throw PartialSuccessError when backend failed to create job stats', async () => {
105
- const apiClientMock = utils_1.getApiClientMock({
105
+ const apiClientMock = (0, utils_1.getApiClientMock)({
106
106
  errorMessage: 'Failed to create stats for job name#12345'
107
107
  }, 202);
108
108
  const queue = getQueue(apiClientMock, 'name');
@@ -118,10 +118,10 @@ describe('Queue methods', () => {
118
118
  }
119
119
  ];
120
120
  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');
121
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
122
122
  });
123
123
  it('should throw PartialSuccessError when there are failed events and backend failed to create job stats', async () => {
124
- const apiClientMock = utils_1.getApiClientMock({
124
+ const apiClientMock = (0, utils_1.getApiClientMock)({
125
125
  errorMessage: 'Failed to create stats for job name#12345',
126
126
  failedEvents: [
127
127
  {
@@ -147,10 +147,10 @@ describe('Queue methods', () => {
147
147
  }
148
148
  }
149
149
  ]));
150
- utils_1.verifyApiClientCalledPushPathWith(apiClientMock, payload, 'name');
150
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
151
151
  });
152
152
  it('should throw InternalServerError', async () => {
153
- const apiClientMock = utils_1.getApiClientMock({
153
+ const apiClientMock = (0, utils_1.getApiClientMock)({
154
154
  message: 'AWS SQS timed out',
155
155
  code: 500,
156
156
  details: 'The request processing has failed because of an unknown error, exception or failure'
@@ -158,19 +158,19 @@ describe('Queue methods', () => {
158
158
  const queue = getQueue(apiClientMock, 'name');
159
159
  const payload = [...Array(9).keys()];
160
160
  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');
161
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
162
162
  });
163
163
  it('should throw InternalServerError for error response without response body', async () => {
164
- const apiClientMock = utils_1.getApiClientMockWithoutResponseBody(504, 'Gateway Timeout');
164
+ const apiClientMock = (0, utils_1.getApiClientMockWithoutResponseBody)(504, 'Gateway Timeout');
165
165
  const queue = getQueue(apiClientMock, 'name');
166
166
  const payload = [1];
167
167
  await expect(queue.push(1)).rejects.toThrow(new errors_1.InternalServerError(`504 Gateway Timeout`, 504));
168
- utils_1.verifyApiClientCalledPushPathWith(apiClientMock, payload, 'name');
168
+ (0, utils_1.verifyApiClientCalledPushPathWith)(apiClientMock, payload, 'name');
169
169
  });
170
170
  });
171
171
  describe('getJob', () => {
172
172
  it('should create a JobProgress by jobId', async () => {
173
- const apiClientMock = utils_1.getApiClientMock();
173
+ const apiClientMock = (0, utils_1.getApiClientMock)();
174
174
  const queue = getQueue(apiClientMock, 'name');
175
175
  const jobProgress = queue.getJob('test-job-id');
176
176
  expect(jobProgress).toEqual(new jobProgress_1.JobProgress('test-job-id', apiClientMock));
@@ -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,gBAAgB,cAAe,GAAG,6CAO9C,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
3
  exports.verifyApiClientCalledPushPathWith = exports.verifyApiClientCalledWith = exports.getApiClientMockWithoutResponseBody = exports.getApiClientMock = void 0;
4
- exports.getApiClientMock = (response, statusCode = 201) => {
4
+ const getApiClientMock = (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.getApiClientMock = getApiClientMock;
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.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");
@@ -15,9 +15,9 @@ class JobProgress {
15
15
  jobId: jobId,
16
16
  time: new Date().toISOString()
17
17
  };
18
- validators_1.validateGetStatsPayload(getStatsRequest);
19
- const response = await queries_1.post(queries_1.GET_STATS_PATH, getStatsRequest, this.apiClient);
20
- await validators_1.validateGetStatsAPIResponse(response, getStatsRequest);
18
+ (0, validators_1.validateGetStatsPayload)(getStatsRequest);
19
+ const response = await (0, queries_1.post)(queries_1.GET_STATS_PATH, getStatsRequest, this.apiClient);
20
+ await (0, validators_1.validateGetStatsAPIResponse)(response, getStatsRequest);
21
21
  return response;
22
22
  }
23
23
  async cancel() {
@@ -27,9 +27,9 @@ class JobProgress {
27
27
  jobId: jobId,
28
28
  time: new Date().toISOString()
29
29
  };
30
- validators_1.validateCancelJobRequest(cancelJobRequest);
31
- const response = await queries_1.post(queries_1.CANCEL_JOB_PATH, cancelJobRequest, this.apiClient);
32
- await validators_1.validateCancelJobAPIResponse(response, cancelJobRequest);
30
+ (0, validators_1.validateCancelJobRequest)(cancelJobRequest);
31
+ const response = await (0, queries_1.post)(queries_1.CANCEL_JOB_PATH, cancelJobRequest, this.apiClient);
32
+ await (0, validators_1.validateCancelJobAPIResponse)(response, cancelJobRequest);
33
33
  return response;
34
34
  }
35
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE/D,eAAO,MAAM,SAAS,0EAA0E,CAAC;AACjG,eAAO,MAAM,cAAc,wEAAwE,CAAC;AACpG,eAAO,MAAM,eAAe,yEAAyE,CAAC;AAEtG,eAAO,MAAM,IAAI,aAAoB,MAAM,QAAQ,UAAU,aAAa,WAAW,KAAG,OAAO,CAAC,WAAW,CAU1G,CAAC"}
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE/D,eAAO,MAAM,SAAS,0EAA0E,CAAC;AACjG,eAAO,MAAM,cAAc,wEAAwE,CAAC;AACpG,eAAO,MAAM,eAAe,yEAAyE,CAAC;AAEtG,eAAO,MAAM,IAAI,aAAoB,MAAM,QAAQ,UAAU,aAAa,WAAW,KAAG,QAAQ,WAAW,CAU1G,CAAC"}
package/out/queries.js CHANGED
@@ -4,7 +4,7 @@ exports.post = exports.CANCEL_JOB_PATH = exports.GET_STATS_PATH = exports.PUSH_P
4
4
  exports.PUSH_PATH = '/webhook/queue/publish/{cloudId}/{environmentId}/{appId}/{appVersion}';
5
5
  exports.GET_STATS_PATH = '/webhook/queue/stats/{cloudId}/{environmentId}/{appId}/{appVersion}';
6
6
  exports.CANCEL_JOB_PATH = '/webhook/queue/cancel/{cloudId}/{environmentId}/{appId}/{appVersion}';
7
- exports.post = async (endpoint, body, apiClient) => {
7
+ const post = async (endpoint, body, apiClient) => {
8
8
  const request = {
9
9
  method: 'POST',
10
10
  body: JSON.stringify(body),
@@ -14,3 +14,4 @@ exports.post = async (endpoint, body, apiClient) => {
14
14
  };
15
15
  return await apiClient(endpoint, request);
16
16
  };
17
+ exports.post = post;
package/out/queue.js CHANGED
@@ -8,14 +8,14 @@ const v4_1 = tslib_1.__importDefault(require("uuid/v4"));
8
8
  const jobProgress_1 = require("./jobProgress");
9
9
  class Queue {
10
10
  constructor(queueParams, apiClient) {
11
- validators_1.validateQueueKey(queueParams.key);
11
+ (0, validators_1.validateQueueKey)(queueParams.key);
12
12
  this.queueParams = queueParams;
13
13
  this.apiClient = apiClient || global.api.asApp().__requestAtlassian;
14
14
  }
15
15
  async push(payloads, pushSettings) {
16
- validators_1.validatePushPayloads(payloads);
16
+ (0, validators_1.validatePushPayloads)(payloads);
17
17
  const queueName = this.queueParams.key;
18
- const jobId = v4_1.default();
18
+ const jobId = (0, v4_1.default)();
19
19
  const pushRequest = {
20
20
  queueName: queueName,
21
21
  jobId: jobId,
@@ -25,13 +25,13 @@ class Queue {
25
25
  time: new Date().toISOString()
26
26
  };
27
27
  if (pushSettings) {
28
- validators_1.validatePushSettings(pushSettings);
28
+ (0, validators_1.validatePushSettings)(pushSettings);
29
29
  if (pushSettings.delayInSeconds) {
30
30
  pushRequest.delayInSeconds = pushSettings.delayInSeconds;
31
31
  }
32
32
  }
33
- const response = await queries_1.post(queries_1.PUSH_PATH, pushRequest, this.apiClient);
34
- await validators_1.validatePushAPIResponse(response, pushRequest);
33
+ const response = await (0, queries_1.post)(queries_1.PUSH_PATH, pushRequest, this.apiClient);
34
+ await (0, validators_1.validatePushAPIResponse)(response, pushRequest);
35
35
  return `${queueName}#${jobId}`;
36
36
  }
37
37
  getJob(jobId) {
package/out/validators.js CHANGED
@@ -6,17 +6,19 @@ const text_1 = require("./text");
6
6
  const VALID_QUEUE_NAME_PATTERN = /^[a-zA-Z0-9-_]+$/;
7
7
  const MAXIMUM_EVENTS = 50;
8
8
  const MAXIMUM_PAYLOAD_SIZE_KB = 200;
9
- exports.validateQueueKey = (queueName) => {
9
+ const validateQueueKey = (queueName) => {
10
10
  if (!queueName || !VALID_QUEUE_NAME_PATTERN.test(queueName)) {
11
11
  throw new errors_1.InvalidQueueNameError(text_1.Text.error.invalidQueueName);
12
12
  }
13
13
  };
14
- exports.validatePushSettings = (settings) => {
14
+ exports.validateQueueKey = validateQueueKey;
15
+ const validatePushSettings = (settings) => {
15
16
  if ((settings.delayInSeconds && settings.delayInSeconds > 900) || settings.delayInSeconds < 0) {
16
17
  throw new errors_1.InvalidPushSettingsError(text_1.Text.error.invalidDelayInSecondsSetting);
17
18
  }
18
19
  };
19
- exports.validatePushPayloads = (payloads) => {
20
+ exports.validatePushSettings = validatePushSettings;
21
+ const validatePushPayloads = (payloads) => {
20
22
  if (!payloads || (Array.isArray(payloads) && payloads.length === 0)) {
21
23
  throw new errors_1.NoEventsToPushError(text_1.Text.error.noEventsPushed);
22
24
  }
@@ -28,19 +30,22 @@ exports.validatePushPayloads = (payloads) => {
28
30
  throw new errors_1.PayloadTooBigError(text_1.Text.error.maxPayloadAllowed(MAXIMUM_PAYLOAD_SIZE_KB));
29
31
  }
30
32
  };
31
- exports.validateGetStatsPayload = (getStatsRequest) => {
33
+ exports.validatePushPayloads = validatePushPayloads;
34
+ const validateGetStatsPayload = (getStatsRequest) => {
32
35
  if (!getStatsRequest.jobId) {
33
36
  throw new errors_1.JobDoesNotExistError(text_1.Text.error.jobIdEmpty);
34
37
  }
35
- exports.validateQueueKey(getStatsRequest.queueName);
38
+ (0, exports.validateQueueKey)(getStatsRequest.queueName);
36
39
  };
37
- exports.validateCancelJobRequest = (cancelJobRequest) => {
40
+ exports.validateGetStatsPayload = validateGetStatsPayload;
41
+ const validateCancelJobRequest = (cancelJobRequest) => {
38
42
  if (!cancelJobRequest.jobId) {
39
43
  throw new errors_1.JobDoesNotExistError(text_1.Text.error.jobIdEmpty);
40
44
  }
41
- exports.validateQueueKey(cancelJobRequest.queueName);
45
+ (0, exports.validateQueueKey)(cancelJobRequest.queueName);
42
46
  };
43
- exports.validateAPIResponse = async (response, expectedSuccessStatus) => {
47
+ exports.validateCancelJobRequest = validateCancelJobRequest;
48
+ const validateAPIResponse = async (response, expectedSuccessStatus) => {
44
49
  if (response.status === 429) {
45
50
  throw new errors_1.RateLimitError(text_1.Text.error.rateLimitError);
46
51
  }
@@ -61,7 +66,8 @@ exports.validateAPIResponse = async (response, expectedSuccessStatus) => {
61
66
  throw internalServerError;
62
67
  }
63
68
  };
64
- exports.validatePushAPIResponse = async (response, requestBody) => {
69
+ exports.validateAPIResponse = validateAPIResponse;
70
+ const validatePushAPIResponse = async (response, requestBody) => {
65
71
  if (response.status === 413) {
66
72
  const responseBody = await response.json();
67
73
  throw new errors_1.PayloadTooBigError(responseBody.errorMessage);
@@ -87,17 +93,20 @@ exports.validatePushAPIResponse = async (response, requestBody) => {
87
93
  }
88
94
  throw partialSuccessError;
89
95
  }
90
- await exports.validateAPIResponse(response, 201);
96
+ await (0, exports.validateAPIResponse)(response, 201);
91
97
  };
92
- exports.validateGetStatsAPIResponse = async (response, getStatsRequest) => {
98
+ exports.validatePushAPIResponse = validatePushAPIResponse;
99
+ const validateGetStatsAPIResponse = async (response, getStatsRequest) => {
93
100
  if (response.status === 404) {
94
101
  throw new errors_1.JobDoesNotExistError(text_1.Text.error.jobDoesNotExit(getStatsRequest.jobId, getStatsRequest.queueName));
95
102
  }
96
- await exports.validateAPIResponse(response, 200);
103
+ await (0, exports.validateAPIResponse)(response, 200);
97
104
  };
98
- exports.validateCancelJobAPIResponse = async (response, cancelJobRequest) => {
105
+ exports.validateGetStatsAPIResponse = validateGetStatsAPIResponse;
106
+ const validateCancelJobAPIResponse = async (response, cancelJobRequest) => {
99
107
  if (response.status === 404) {
100
108
  throw new errors_1.JobDoesNotExistError(text_1.Text.error.jobDoesNotExit(cancelJobRequest.jobId, cancelJobRequest.queueName));
101
109
  }
102
- await exports.validateAPIResponse(response, 204);
110
+ await (0, exports.validateAPIResponse)(response, 204);
103
111
  };
112
+ exports.validateCancelJobAPIResponse = validateCancelJobAPIResponse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/events",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Forge Async Event methods",
5
5
  "author": "Atlassian",
6
6
  "license": "UNLICENSED",
@@ -16,7 +16,7 @@
16
16
  "@types/uuid": "^3.4.7"
17
17
  },
18
18
  "dependencies": {
19
- "@forge/api": "^2.7.0",
19
+ "@forge/api": "^2.8.0",
20
20
  "uuid": "^3.4.0"
21
21
  }
22
22
  }