@forge/events 0.0.0-experimental-e05f7a2 → 0.0.0-experimental-64caa5a

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 (60) hide show
  1. package/CHANGELOG.md +154 -1
  2. package/README.md +1 -1
  3. package/out/__test__/jobProgress.test.d.ts +2 -0
  4. package/out/__test__/jobProgress.test.d.ts.map +1 -0
  5. package/out/__test__/jobProgress.test.js +110 -0
  6. package/out/__test__/queue.test.d.ts +2 -0
  7. package/out/__test__/queue.test.d.ts.map +1 -0
  8. package/out/__test__/queue.test.js +179 -0
  9. package/out/__test__/queueResponse.test.d.ts +2 -0
  10. package/out/__test__/queueResponse.test.d.ts.map +1 -0
  11. package/out/__test__/queueResponse.test.js +14 -0
  12. package/out/__test__/utils.d.ts +7 -0
  13. package/out/__test__/utils.d.ts.map +1 -0
  14. package/out/__test__/utils.js +37 -0
  15. package/out/errors.d.ts +9 -0
  16. package/out/errors.d.ts.map +1 -1
  17. package/out/errors.js +19 -1
  18. package/out/index.d.ts +3 -0
  19. package/out/index.d.ts.map +1 -1
  20. package/out/index.js +15 -0
  21. package/out/jobProgress.d.ts +9 -0
  22. package/out/jobProgress.d.ts.map +1 -0
  23. package/out/jobProgress.js +36 -0
  24. package/out/queries.d.ts +4 -2
  25. package/out/queries.d.ts.map +1 -1
  26. package/out/queries.js +13 -8
  27. package/out/queue.d.ts +4 -4
  28. package/out/queue.d.ts.map +1 -1
  29. package/out/queue.js +25 -25
  30. package/out/queueResponse.d.ts +5 -0
  31. package/out/queueResponse.d.ts.map +1 -0
  32. package/out/queueResponse.js +12 -0
  33. package/out/text.d.ts +14 -0
  34. package/out/text.d.ts.map +1 -0
  35. package/out/text.js +16 -0
  36. package/out/types.d.ts +11 -4
  37. package/out/types.d.ts.map +1 -1
  38. package/out/validators.d.ts +10 -4
  39. package/out/validators.d.ts.map +1 -1
  40. package/out/validators.js +69 -18
  41. package/package.json +7 -2
  42. package/src/__test__/jobProgress.test.ts +149 -0
  43. package/src/__test__/queue.test.ts +236 -0
  44. package/src/__test__/queueResponse.test.ts +14 -0
  45. package/src/__test__/utils.ts +47 -0
  46. package/src/errors.ts +18 -0
  47. package/src/index.ts +14 -0
  48. package/src/jobProgress.ts +48 -0
  49. package/src/queries.ts +15 -9
  50. package/src/queue.ts +28 -29
  51. package/src/queueResponse.ts +7 -0
  52. package/src/text.ts +15 -0
  53. package/src/types.ts +12 -4
  54. package/src/validators.ts +98 -31
  55. package/tsconfig.json +12 -9
  56. package/tsconfig.tsbuildinfo +107 -20
  57. package/out/__test__/index.test.d.ts +0 -2
  58. package/out/__test__/index.test.d.ts.map +0 -1
  59. package/out/__test__/index.test.js +0 -126
  60. package/src/__test__/index.test.ts +0 -168
package/src/validators.ts CHANGED
@@ -1,44 +1,95 @@
1
1
  import {
2
2
  InternalServerError,
3
3
  InvalidQueueNameError,
4
+ JobDoesNotExistError,
4
5
  NoEventsToPushError,
5
6
  PartialSuccessError,
6
7
  PayloadTooBigError,
7
8
  RateLimitError,
8
- TooManyEventsError
9
+ TooManyEventsError,
10
+ InvalidPushSettingsError,
11
+ InvocationLimitReachedError
9
12
  } from './errors';
10
- import { APIResponse, Payload, APIRequest } from './types';
13
+ import { Text } from './text';
14
+ import { APIResponse, CancelJobRequest, GetStatsRequest, Payload, PushRequest, PushSettings } from './types';
11
15
 
12
16
  const VALID_QUEUE_NAME_PATTERN = /^[a-zA-Z0-9-_]+$/;
13
- const MAXIMUM_EVENTS = 10;
17
+ const MAXIMUM_EVENTS = 50;
14
18
  const MAXIMUM_PAYLOAD_SIZE_KB = 200;
15
19
 
16
- export const validateQueueName = (queueName: string) => {
20
+ export const validateQueueKey = (queueName: string) => {
17
21
  if (!queueName || !VALID_QUEUE_NAME_PATTERN.test(queueName)) {
18
- throw new InvalidQueueNameError('Queue name can only contain alphanumeric, dash and underscore characters');
22
+ throw new InvalidQueueNameError(Text.error.invalidQueueName);
19
23
  }
20
24
  };
21
25
 
22
- export const validatePayloads = (payloads: Payload | Payload[]) => {
26
+ export const validatePushSettings = (settings: PushSettings) => {
27
+ if ((settings.delayInSeconds && settings.delayInSeconds > 900) || settings.delayInSeconds < 0) {
28
+ throw new InvalidPushSettingsError(Text.error.invalidDelayInSecondsSetting);
29
+ }
30
+ };
31
+
32
+ export const validatePushPayloads = (payloads: Payload | Payload[]) => {
23
33
  if (!payloads || (Array.isArray(payloads) && payloads.length === 0)) {
24
- throw new NoEventsToPushError(`No events pushed`);
34
+ throw new NoEventsToPushError(Text.error.noEventsPushed);
25
35
  }
26
36
 
27
37
  if (Array.isArray(payloads) && payloads.length > MAXIMUM_EVENTS) {
28
- throw new TooManyEventsError(`Maximum of ${MAXIMUM_EVENTS} events allowed in a single push`);
38
+ throw new TooManyEventsError(Text.error.maxEventsAllowed(MAXIMUM_EVENTS));
29
39
  }
30
40
 
31
41
  const payloadSizeKB = Buffer.byteLength(JSON.stringify(payloads)) / 1024;
32
42
  if (payloadSizeKB > MAXIMUM_PAYLOAD_SIZE_KB) {
33
- throw new PayloadTooBigError(`The maximum payload size allowed is ${MAXIMUM_PAYLOAD_SIZE_KB}KB`);
43
+ throw new PayloadTooBigError(Text.error.maxPayloadAllowed(MAXIMUM_PAYLOAD_SIZE_KB));
44
+ }
45
+ };
46
+
47
+ export const validateGetStatsPayload = (getStatsRequest: GetStatsRequest) => {
48
+ if (!getStatsRequest.jobId) {
49
+ throw new JobDoesNotExistError(Text.error.jobIdEmpty);
50
+ }
51
+ validateQueueKey(getStatsRequest.queueName);
52
+ };
53
+
54
+ export const validateCancelJobRequest = (cancelJobRequest: CancelJobRequest) => {
55
+ if (!cancelJobRequest.jobId) {
56
+ throw new JobDoesNotExistError(Text.error.jobIdEmpty);
34
57
  }
58
+ validateQueueKey(cancelJobRequest.queueName);
35
59
  };
36
60
 
37
- export const validateAPIResponse = async (response: APIResponse, requestBody: APIRequest) => {
61
+ export const validateAPIResponse = async (response: APIResponse, expectedSuccessStatus: number) => {
38
62
  if (response.status === 429) {
39
- throw new RateLimitError(`Too many requests`);
63
+ throw new RateLimitError(Text.error.rateLimitError);
40
64
  }
41
65
 
66
+ if (response.status === 405) {
67
+ throw new InvocationLimitReachedError(Text.error.invocationLimitReachedError);
68
+ }
69
+
70
+ if (response.status != expectedSuccessStatus && response.status) {
71
+ //Catch all errors from server that we have not handled
72
+ let internalServerError;
73
+
74
+ try {
75
+ const responseBody = await response.json();
76
+ const errorMessage = responseBody.message ? `: ${responseBody.message}` : '';
77
+ const errors = responseBody.errors ? `: ${responseBody.errors.join(', ')}` : ''; //Dropwizard returns an array of errors when request body validation failed
78
+ internalServerError = new InternalServerError(
79
+ `${response.status} ${response.statusText}${errorMessage}${errors}`,
80
+ responseBody.code,
81
+ responseBody.details
82
+ );
83
+ } catch (ignore) {
84
+ //response body is not a json
85
+ internalServerError = new InternalServerError(`${response.status} ${response.statusText}`, response.status);
86
+ }
87
+
88
+ throw internalServerError;
89
+ }
90
+ };
91
+
92
+ export const validatePushAPIResponse = async (response: APIResponse, requestBody: PushRequest) => {
42
93
  if (response.status === 413) {
43
94
  //Server can return this error response if it has a different max payload size and max number of events limits
44
95
  const responseBody = await response.json();
@@ -47,29 +98,45 @@ export const validateAPIResponse = async (response: APIResponse, requestBody: AP
47
98
 
48
99
  if (response.status === 202) {
49
100
  const responseBody = await response.json();
101
+ const defaultErrorMessage = 'Failed to process some events.';
102
+ const partialSuccessError = new PartialSuccessError(defaultErrorMessage, []);
103
+
50
104
  if (responseBody.failedEvents && responseBody.failedEvents.length > 0) {
51
- throw new PartialSuccessError(
52
- `Failed to process ${responseBody.failedEvents.length} events`,
53
- responseBody.failedEvents.map((failedEvent: any) => {
54
- return {
55
- errorMessage: failedEvent.errorMessage,
56
- payload: requestBody.payload[+failedEvent.index]
57
- };
58
- })
59
- );
60
- } else {
61
- throw new PartialSuccessError(`Failed to process events`, []);
105
+ partialSuccessError.message = `Failed to process ${responseBody.failedEvents.length} event(s).`;
106
+ partialSuccessError.failedEvents = responseBody.failedEvents.map((failedEvent: any) => {
107
+ return {
108
+ errorMessage: failedEvent.errorMessage,
109
+ payload: requestBody.payload[+failedEvent.index]
110
+ };
111
+ });
62
112
  }
113
+
114
+ if (responseBody.errorMessage) {
115
+ //Append any extra error message from backend
116
+ partialSuccessError.message =
117
+ partialSuccessError.message !== defaultErrorMessage
118
+ ? `${partialSuccessError.message} ${responseBody.errorMessage}`
119
+ : responseBody.errorMessage;
120
+ }
121
+
122
+ throw partialSuccessError;
63
123
  }
64
124
 
65
- if (response.status != 201 && response.status) {
66
- //Catch all errors from server that we have not handled
67
- const responseBody = await response.json();
68
- const errorMessage = responseBody.message ? `: ${responseBody.message}` : '';
69
- throw new InternalServerError(
70
- `${response.status} ${response.statusText}${errorMessage}`,
71
- responseBody.code,
72
- responseBody.details
73
- );
125
+ await validateAPIResponse(response, 201);
126
+ };
127
+
128
+ export const validateGetStatsAPIResponse = async (response: APIResponse, getStatsRequest: GetStatsRequest) => {
129
+ if (response.status === 404) {
130
+ throw new JobDoesNotExistError(Text.error.jobDoesNotExit(getStatsRequest.jobId, getStatsRequest.queueName));
131
+ }
132
+
133
+ await validateAPIResponse(response, 200);
134
+ };
135
+
136
+ export const validateCancelJobAPIResponse = async (response: APIResponse, cancelJobRequest: GetStatsRequest) => {
137
+ if (response.status === 404) {
138
+ throw new JobDoesNotExistError(Text.error.jobDoesNotExit(cancelJobRequest.jobId, cancelJobRequest.queueName));
74
139
  }
140
+
141
+ await validateAPIResponse(response, 204);
75
142
  };
package/tsconfig.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
- "extends": "../../tsconfig-base.json",
3
- "compilerOptions": {
4
- "outDir": "./out",
5
- "rootDir": "src",
6
- "composite": true
7
- },
8
- "references": []
9
- }
10
-
2
+ "extends": "../../tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./out",
5
+ "rootDir": "src",
6
+ "composite": true
7
+ },
8
+ "references": [
9
+ {
10
+ "path": "../forge-api"
11
+ }
12
+ ]
13
+ }
@@ -392,38 +392,78 @@
392
392
  "affectsGlobalScope": false
393
393
  },
394
394
  "./src/types.ts": {
395
- "version": "d47d6c53ca38a8fd0680ae2b37f593678cbf8f601a8fc8d1a0efc0b70eedc0ae",
396
- "signature": "d30f169ca276a9c30db76677f0c9594cb2ef1154e1453dcbc845a07c6fa80179",
395
+ "version": "d899396a1cd22fa15d0aa6157f0cfd2e2e6d4548a26bf78b1ab60f1df3f4a297",
396
+ "signature": "bd30bbb87257959ac77e41c2f1b05f36adc4df30395152b645663c4d27c47cb8",
397
397
  "affectsGlobalScope": false
398
398
  },
399
399
  "./src/errors.ts": {
400
- "version": "316ddc35ca8bcf0bbb7e6d0e935adef5f3c1e6405b69e316812bdb4e52a54d4f",
401
- "signature": "bebd9a1e0429bfee8f7d8eaa466cc18a1c239d8b2ddb93aee13d9cd5d66fc982",
400
+ "version": "d851b9c7d9f3221bbef29df8237e3d4156ab8706950d6bdd6c4a57d8e55cc4c1",
401
+ "signature": "dbec5f26319c68d139585561f12341a720ab13880a4c040b438e892ae391d2c9",
402
402
  "affectsGlobalScope": false
403
403
  },
404
404
  "./src/queries.ts": {
405
- "version": "bf5a5b99ef72ed07facc6023ee14525cb84cb1196fc2fffa4b2b37907a532086",
406
- "signature": "7bc0242e0383e454dcd12f7bad5b5cf2bf9dcc445ec18c2a2793346f1198444b",
405
+ "version": "37ef341ab46e3c19f69adca1eaa01e6d8718492817de0fd6d2ec8c8a12d08a53",
406
+ "signature": "f2c2560bfd355b9314099a4fbf9590389a05a631a0de38c45f58138b62de8373",
407
+ "affectsGlobalScope": false
408
+ },
409
+ "./src/text.ts": {
410
+ "version": "0b4ee00634da4bf5aa2fecf99443c7a886fee5619832b35c0e10513deecd3967",
411
+ "signature": "4c846733296e27a117c12a9bdf0311f5790125ddf1e1e01b54869b9c487630ba",
407
412
  "affectsGlobalScope": false
408
413
  },
409
414
  "./src/validators.ts": {
410
- "version": "72bc6c4d9c634c4c96507d1da722b4207821955bd864e1c758dac645f8b12aa3",
411
- "signature": "491750f8257f1ef8c305645833cc8c6feb309aef26377a6fca3a15ac0bd3df5b",
415
+ "version": "80bad79d153f9cbadb49786888e0bf8afa8b1cade29ddb7a6abf41a549a7d189",
416
+ "signature": "1caad0a449141b7fb074e18fa2b8668551d6cff6b60ca3611b99e98a9269c1b2",
417
+ "affectsGlobalScope": false
418
+ },
419
+ "../../node_modules/@types/uuid/interfaces.d.ts": {
420
+ "version": "60ea69b95f7bad47f3e6cb8a695a53f5a1e58c2d0fb2c1b4c4adc923b06b7484",
421
+ "signature": "60ea69b95f7bad47f3e6cb8a695a53f5a1e58c2d0fb2c1b4c4adc923b06b7484",
422
+ "affectsGlobalScope": false
423
+ },
424
+ "../../node_modules/@types/uuid/v4.d.ts": {
425
+ "version": "92a833e8bc8549bcfdeb41bb2ad0981584bbaa84f77ec42d561ce15e9e0f4261",
426
+ "signature": "92a833e8bc8549bcfdeb41bb2ad0981584bbaa84f77ec42d561ce15e9e0f4261",
427
+ "affectsGlobalScope": false
428
+ },
429
+ "./src/jobProgress.ts": {
430
+ "version": "5e1a2c3330fa7dcfd92a4b12cddfba84ff23110637ed768a2a139568ea966364",
431
+ "signature": "34c50ef91fedd3e185ce8913f72f6aa106e52387267de30bfcc0f6dc61148085",
412
432
  "affectsGlobalScope": false
413
433
  },
414
434
  "./src/queue.ts": {
415
- "version": "94d3c3b228c3b1cdf58ed95623e0ba471692fa5c720352e209c507cb22a3fc6a",
416
- "signature": "630728b629737804ad4612eb0d7b2bbe1f98c388ebf02f1b71bca84e49a2da38",
435
+ "version": "d72cac54a753262765b64ec81d5491d0440578220a76023c536e6073bbb29695",
436
+ "signature": "4ea1b1f30f2e0d5450e34add970982ff573ffaeb740bb7df9342f35c9e3967e8",
437
+ "affectsGlobalScope": false
438
+ },
439
+ "./src/queueResponse.ts": {
440
+ "version": "33b9a3503cda389709cdd6534506ab6e42c71acc96484e3e1d9e210a683f4494",
441
+ "signature": "1b85e7520c5ba8dc1778ea26fd4598517ff952d0856e88664fcd6790dd7dec89",
417
442
  "affectsGlobalScope": false
418
443
  },
419
444
  "./src/index.ts": {
420
- "version": "4abb81fd11b585c0641517c4810c3d4c4da0869be5c538be61f4821fdfbfaadb",
421
- "signature": "56b74ac182986e3df3f15fe95a2018e0b0860544e15d2b1085bdb7755e695f80",
445
+ "version": "819f518efd3928f9c31e16d47d1b7bd35a9bb526e40ead733207a8baa588f36f",
446
+ "signature": "21cbc64a6c05b3d549fdfe6a03dffc365efc2fe08b069cf28eae61f1a1a0f589",
422
447
  "affectsGlobalScope": false
423
448
  },
424
- "./src/__test__/index.test.ts": {
425
- "version": "9a6c68de324652b74c200f0a6b2039031b6d4bdb29747d9a8c14072e1730b403",
426
- "signature": "8b8ff3ac6a533fdfd68ca0f9c056c4a0f88dd9cd14c972d61ed643a7bcf7a887",
449
+ "./src/__test__/utils.ts": {
450
+ "version": "95ade8f141f5183aeaddd527eff7132ddf355cdaa75906171c1c64e2a01e6bf4",
451
+ "signature": "4e1f805ae42006f2f17e945ca6d7e15d88097082e09a39c8598fac22151042d8",
452
+ "affectsGlobalScope": false
453
+ },
454
+ "./src/__test__/jobProgress.test.ts": {
455
+ "version": "21f544b34d81798a4c229e4b8834f69561400e56fb260b94cd533e4223a24740",
456
+ "signature": "7870ceffd2c069795d2976c13017e1697f28e9a1c994dbd36dc48c21826db61b",
457
+ "affectsGlobalScope": false
458
+ },
459
+ "./src/__test__/queue.test.ts": {
460
+ "version": "23dea05f9460582f60526e93a77111cda92508c785087c54fa05995b9b6dd9df",
461
+ "signature": "1302e8032e32981552bc73b7ef2f99ebf98990a704e26f51e70b1d96a4639fcf",
462
+ "affectsGlobalScope": false
463
+ },
464
+ "./src/__test__/queueResponse.test.ts": {
465
+ "version": "1284a9873c9417bee3eaed6085415783492678d52fe520e41a308f067bdf5a17",
466
+ "signature": "7bc819d10bb62166250f5efeffe176508b3d870807ac87f9fd987e3a552a9b64",
427
467
  "affectsGlobalScope": false
428
468
  },
429
469
  "../../node_modules/jest-diff/build/cleanupSemantic.d.ts": {
@@ -658,6 +698,9 @@
658
698
  "../../node_modules/@types/node/zlib.d.ts": [
659
699
  "../../node_modules/@types/node/stream.d.ts"
660
700
  ],
701
+ "../../node_modules/@types/uuid/v4.d.ts": [
702
+ "../../node_modules/@types/uuid/interfaces.d.ts"
703
+ ],
661
704
  "../../node_modules/form-data/index.d.ts": [
662
705
  "../../node_modules/@types/node/http.d.ts",
663
706
  "../../node_modules/@types/node/index.d.ts",
@@ -680,21 +723,43 @@
680
723
  "../../node_modules/pretty-format/build/index.d.ts": [
681
724
  "../../node_modules/pretty-format/build/types.d.ts"
682
725
  ],
683
- "./src/__test__/index.test.ts": [
726
+ "./src/__test__/jobProgress.test.ts": [
727
+ "./src/__test__/utils.ts",
684
728
  "./src/errors.ts",
685
- "./src/queue.ts",
729
+ "./src/jobProgress.ts"
730
+ ],
731
+ "./src/__test__/queue.test.ts": [
732
+ "./src/__test__/utils.ts",
733
+ "./src/errors.ts",
734
+ "./src/jobProgress.ts",
735
+ "./src/queue.ts"
736
+ ],
737
+ "./src/__test__/queueResponse.test.ts": [
738
+ "./src/queueResponse.ts"
739
+ ],
740
+ "./src/__test__/utils.ts": [
686
741
  "./src/types.ts"
687
742
  ],
688
743
  "./src/errors.ts": [
689
744
  "./src/types.ts"
690
745
  ],
691
746
  "./src/index.ts": [
692
- "./src/queue.ts"
747
+ "./src/errors.ts",
748
+ "./src/jobProgress.ts",
749
+ "./src/queue.ts",
750
+ "./src/queueResponse.ts"
751
+ ],
752
+ "./src/jobProgress.ts": [
753
+ "./src/queries.ts",
754
+ "./src/types.ts",
755
+ "./src/validators.ts"
693
756
  ],
694
757
  "./src/queries.ts": [
695
758
  "./src/types.ts"
696
759
  ],
697
760
  "./src/queue.ts": [
761
+ "../../node_modules/@types/uuid/v4.d.ts",
762
+ "./src/jobProgress.ts",
698
763
  "./src/queries.ts",
699
764
  "./src/types.ts",
700
765
  "./src/validators.ts"
@@ -704,6 +769,7 @@
704
769
  ],
705
770
  "./src/validators.ts": [
706
771
  "./src/errors.ts",
772
+ "./src/text.ts",
707
773
  "./src/types.ts"
708
774
  ]
709
775
  },
@@ -868,6 +934,9 @@
868
934
  "../../node_modules/@types/node/zlib.d.ts": [
869
935
  "../../node_modules/@types/node/stream.d.ts"
870
936
  ],
937
+ "../../node_modules/@types/uuid/v4.d.ts": [
938
+ "../../node_modules/@types/uuid/interfaces.d.ts"
939
+ ],
871
940
  "../../node_modules/form-data/index.d.ts": [
872
941
  "../../node_modules/@types/node/http.d.ts",
873
942
  "../../node_modules/@types/node/index.d.ts",
@@ -890,16 +959,26 @@
890
959
  "../../node_modules/pretty-format/build/index.d.ts": [
891
960
  "../../node_modules/pretty-format/build/types.d.ts"
892
961
  ],
962
+ "./src/__test__/utils.ts": [
963
+ "./src/types.ts"
964
+ ],
893
965
  "./src/errors.ts": [
894
966
  "./src/types.ts"
895
967
  ],
896
968
  "./src/index.ts": [
897
- "./src/queue.ts"
969
+ "./src/errors.ts",
970
+ "./src/jobProgress.ts",
971
+ "./src/queue.ts",
972
+ "./src/queueResponse.ts"
973
+ ],
974
+ "./src/jobProgress.ts": [
975
+ "./src/types.ts"
898
976
  ],
899
977
  "./src/queries.ts": [
900
978
  "./src/types.ts"
901
979
  ],
902
980
  "./src/queue.ts": [
981
+ "./src/jobProgress.ts",
903
982
  "./src/types.ts"
904
983
  ],
905
984
  "./src/types.ts": [
@@ -960,6 +1039,8 @@
960
1039
  "../../node_modules/@types/node/wasi.d.ts",
961
1040
  "../../node_modules/@types/node/worker_threads.d.ts",
962
1041
  "../../node_modules/@types/node/zlib.d.ts",
1042
+ "../../node_modules/@types/uuid/interfaces.d.ts",
1043
+ "../../node_modules/@types/uuid/v4.d.ts",
963
1044
  "../../node_modules/form-data/index.d.ts",
964
1045
  "../../node_modules/jest-diff/build/cleanupSemantic.d.ts",
965
1046
  "../../node_modules/jest-diff/build/diffLines.d.ts",
@@ -996,11 +1077,17 @@
996
1077
  "../../node_modules/typescript/lib/lib.es2020.bigint.d.ts",
997
1078
  "../../node_modules/typescript/lib/lib.es5.d.ts",
998
1079
  "../../node_modules/typescript/lib/lib.esnext.intl.d.ts",
999
- "./src/__test__/index.test.ts",
1080
+ "./src/__test__/jobProgress.test.ts",
1081
+ "./src/__test__/queue.test.ts",
1082
+ "./src/__test__/queueResponse.test.ts",
1083
+ "./src/__test__/utils.ts",
1000
1084
  "./src/errors.ts",
1001
1085
  "./src/index.ts",
1086
+ "./src/jobProgress.ts",
1002
1087
  "./src/queries.ts",
1003
1088
  "./src/queue.ts",
1089
+ "./src/queueResponse.ts",
1090
+ "./src/text.ts",
1004
1091
  "./src/types.ts",
1005
1092
  "./src/validators.ts"
1006
1093
  ]
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/__test__/index.test.ts"],"names":[],"mappings":""}
@@ -1,126 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const queue_1 = require("../queue");
4
- const errors_1 = require("../errors");
5
- const getApiClientMock = (response, statusCode = 201) => {
6
- return jest.fn().mockReturnValue({
7
- created: statusCode === 201,
8
- status: statusCode,
9
- statusText: 'Status Text',
10
- json: jest.fn().mockResolvedValue(response)
11
- });
12
- };
13
- const getQueue = (apiClientMock, queueName) => new queue_1.Queue({ queueName: queueName }, apiClientMock);
14
- const verifyApiClientCalledWith = (apiClientMock, payloads, name) => {
15
- expect(apiClientMock).toHaveBeenCalledWith('/webhook/queue/publish/{cloudId}/{environmentId}/{appId}/{appVersion}', expect.objectContaining({
16
- method: 'POST',
17
- body: expect.any(String),
18
- headers: {
19
- 'content-type': 'application/json'
20
- }
21
- }));
22
- const [, { body }] = apiClientMock.mock.calls[0];
23
- const expectedBody = {
24
- queueName: name,
25
- schema: 'ari:cloud:ecosystem::forge/app-event',
26
- type: 'avi:forge:app:event',
27
- payload: payloads
28
- };
29
- expect(JSON.parse(body)).toEqual(expect.objectContaining(expectedBody));
30
- };
31
- describe('Queue methods', () => {
32
- describe('constructor', () => {
33
- it('should throw InvalidQueueNameError', async () => {
34
- const apiClientMock = getApiClientMock();
35
- expect(() => getQueue(apiClientMock, 'invalid name')).toThrowError(new errors_1.InvalidQueueNameError('Queue name can only contain alphanumeric, dash and underscore characters'));
36
- });
37
- });
38
- describe('push', () => {
39
- it('should call the queue/publish endpoint', async () => {
40
- const apiClientMock = getApiClientMock();
41
- const queue = getQueue(apiClientMock, 'name');
42
- const payload = {
43
- page: 1
44
- };
45
- await queue.push([payload]);
46
- verifyApiClientCalledWith(apiClientMock, [payload], 'name');
47
- });
48
- it('should throw NoEventsToPushError', async () => {
49
- const apiClientMock = getApiClientMock();
50
- const queue = getQueue(apiClientMock, 'name');
51
- await expect(queue.push([])).rejects.toThrow(new errors_1.NoEventsToPushError(`No events pushed`));
52
- expect(apiClientMock).toHaveBeenCalledTimes(0);
53
- });
54
- it('should throw TooManyEventsError', async () => {
55
- const apiClientMock = getApiClientMock();
56
- const queue = getQueue(apiClientMock, 'name');
57
- await expect(queue.push([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])).rejects.toThrow(new errors_1.TooManyEventsError(`Maximum of 10 events allowed in a single push`));
58
- expect(apiClientMock).toHaveBeenCalledTimes(0);
59
- });
60
- it('should throw PayloadTooBigError', async () => {
61
- const apiClientMock = getApiClientMock();
62
- const queue = getQueue(apiClientMock, 'name');
63
- await expect(queue.push('x'.repeat(201 * 1024))).rejects.toThrow(new errors_1.PayloadTooBigError(`The maximum payload size allowed is 200KB`));
64
- expect(apiClientMock).toHaveBeenCalledTimes(0);
65
- });
66
- it('should throw RateLimitError', async () => {
67
- const apiClientMock = getApiClientMock({}, 429);
68
- const queue = getQueue(apiClientMock, 'name');
69
- const payload = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
70
- await expect(queue.push(payload)).rejects.toThrow(new errors_1.RateLimitError(`Too many requests`));
71
- verifyApiClientCalledWith(apiClientMock, payload, 'name');
72
- });
73
- it('should throw PartialSuccessError', async () => {
74
- const apiClientMock = getApiClientMock({
75
- failedEvents: [
76
- {
77
- index: '0',
78
- errorMessage: 'failed-1'
79
- },
80
- {
81
- index: 2,
82
- errorMessage: 'failed-3'
83
- }
84
- ]
85
- }, 202);
86
- const queue = getQueue(apiClientMock, 'name');
87
- const payload = [
88
- {
89
- content: 'payload-1'
90
- },
91
- {
92
- content: 'payload-2'
93
- },
94
- {
95
- content: 'payload-3'
96
- }
97
- ];
98
- await expect(queue.push(payload)).rejects.toThrow(new errors_1.PartialSuccessError(`Failed to process 2 events`, [
99
- {
100
- errorMessage: 'failed-1',
101
- payload: {
102
- content: 'payload-1'
103
- }
104
- },
105
- {
106
- errorMessage: 'failed-3',
107
- payload: {
108
- content: 'payload-3'
109
- }
110
- }
111
- ]));
112
- verifyApiClientCalledWith(apiClientMock, payload, 'name');
113
- });
114
- it('should throw InternalServerError', async () => {
115
- const apiClientMock = getApiClientMock({
116
- message: 'AWS SQS timed out',
117
- code: 500,
118
- details: 'The request processing has failed because of an unknown error, exception or failure'
119
- }, 500);
120
- const queue = getQueue(apiClientMock, 'name');
121
- const payload = [1, 2, 3, 4, 5, 6, 7, 8, 9];
122
- 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'));
123
- verifyApiClientCalledWith(apiClientMock, payload, 'name');
124
- });
125
- });
126
- });