@commercetools-frontend-extensions/operations 3.4.0 → 3.5.0

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 (33) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/commercetools-frontend-extensions-operations.cjs.dev.js +150 -41
  3. package/dist/commercetools-frontend-extensions-operations.cjs.prod.js +150 -41
  4. package/dist/commercetools-frontend-extensions-operations.esm.js +141 -42
  5. package/dist/declarations/src/@errors/base.d.ts +19 -0
  6. package/dist/declarations/src/@errors/guards.d.ts +12 -0
  7. package/dist/declarations/src/@errors/http-error.d.ts +4 -1
  8. package/dist/declarations/src/@errors/index.d.ts +3 -0
  9. package/dist/declarations/src/@errors/invalid-response-error.d.ts +4 -1
  10. package/dist/declarations/src/@errors/no-resources-to-export-error.d.ts +4 -1
  11. package/dist/declarations/src/@errors/polling-aborted-error.d.ts +4 -1
  12. package/dist/declarations/src/@errors/polling-timeout-error.d.ts +8 -0
  13. package/dist/declarations/src/@errors/project-key-not-available-error.d.ts +4 -1
  14. package/dist/declarations/src/@errors/query-predicate-error.d.ts +5 -2
  15. package/dist/declarations/src/@errors/unexpected-column-error.d.ts +5 -1
  16. package/dist/declarations/src/@errors/unexpected-operation-state-error.d.ts +5 -1
  17. package/dist/declarations/src/@errors/unexpected-resource-type-error.d.ts +5 -1
  18. package/package.json +1 -1
  19. package/src/@errors/base.ts +30 -0
  20. package/src/@errors/guards.ts +43 -0
  21. package/src/@errors/http-error.ts +5 -1
  22. package/src/@errors/index.ts +3 -0
  23. package/src/@errors/invalid-response-error.ts +6 -1
  24. package/src/@errors/no-resources-to-export-error.ts +6 -1
  25. package/src/@errors/polling-aborted-error.ts +6 -1
  26. package/src/@errors/polling-timeout-error.ts +17 -0
  27. package/src/@errors/project-key-not-available-error.ts +6 -1
  28. package/src/@errors/query-predicate-error.ts +6 -2
  29. package/src/@errors/unexpected-column-error.ts +8 -1
  30. package/src/@errors/unexpected-operation-state-error.ts +7 -1
  31. package/src/@errors/unexpected-resource-type-error.ts +8 -1
  32. package/src/@utils/poll-job-until-processing.ts +3 -6
  33. package/src/@utils/poll-job-until-validated.ts +3 -6
@@ -0,0 +1,17 @@
1
+ import { ErrorCode, OperationsError } from './base'
2
+
3
+ export class PollingTimeoutError extends OperationsError {
4
+ readonly code = ErrorCode.POLLING_TIMEOUT
5
+ readonly isRetryable = true
6
+ readonly maxAttempts: number
7
+ readonly totalTimeSeconds: number
8
+
9
+ constructor(maxAttempts: number, totalTimeSeconds: number) {
10
+ super(
11
+ `Polling timeout after ${maxAttempts} attempts (${totalTimeSeconds}s)`
12
+ )
13
+ this.name = 'PollingTimeoutError'
14
+ this.maxAttempts = maxAttempts
15
+ this.totalTimeSeconds = totalTimeSeconds
16
+ }
17
+ }
@@ -1,4 +1,9 @@
1
- export class ProjectKeyNotAvailableError extends Error {
1
+ import { ErrorCode, OperationsError } from './base'
2
+
3
+ export class ProjectKeyNotAvailableError extends OperationsError {
4
+ readonly code = ErrorCode.PROJECT_KEY_NOT_AVAILABLE
5
+ readonly isRetryable = false
6
+
2
7
  constructor(message: string = 'Project key is not available') {
3
8
  super(message)
4
9
  this.name = 'ProjectKeyNotAvailableError'
@@ -1,5 +1,9 @@
1
- export class QueryPredicateError extends Error {
2
- field = 'queryPredicate'
1
+ import { ErrorCode, OperationsError } from './base'
2
+
3
+ export class QueryPredicateError extends OperationsError {
4
+ readonly code = ErrorCode.QUERY_PREDICATE_ERROR
5
+ readonly isRetryable = false
6
+ readonly field = 'queryPredicate'
3
7
 
4
8
  constructor(
5
9
  message: string = 'There is an error with the query predicate. Make sure the syntax is correct.'
@@ -1,6 +1,13 @@
1
- export class UnexpectedColumnError extends Error {
1
+ import { ErrorCode, OperationsError } from './base'
2
+
3
+ export class UnexpectedColumnError extends OperationsError {
4
+ readonly code = ErrorCode.UNEXPECTED_COLUMN
5
+ readonly isRetryable = false
6
+ readonly columnName: string
7
+
2
8
  constructor(columnName: string) {
3
9
  super(`Unexpected column "${columnName}"`)
4
10
  this.name = 'UnexpectedColumnError'
11
+ this.columnName = columnName
5
12
  }
6
13
  }
@@ -1,8 +1,14 @@
1
1
  import { ProcessingState } from '@commercetools/importapi-sdk'
2
+ import { ErrorCode, OperationsError } from './base'
3
+
4
+ export class UnexpectedOperationStateError extends OperationsError {
5
+ readonly code = ErrorCode.UNEXPECTED_OPERATION_STATE
6
+ readonly isRetryable = false
7
+ readonly state: ProcessingState
2
8
 
3
- export class UnexpectedOperationStateError extends Error {
4
9
  constructor(state: ProcessingState) {
5
10
  super(`Unexpected operation state "${state}"`)
6
11
  this.name = 'UnexpectedOperationStateError'
12
+ this.state = state
7
13
  }
8
14
  }
@@ -1,6 +1,13 @@
1
- export class UnexpectedResourceTypeError extends Error {
1
+ import { ErrorCode, OperationsError } from './base'
2
+
3
+ export class UnexpectedResourceTypeError extends OperationsError {
4
+ readonly code = ErrorCode.UNEXPECTED_RESOURCE_TYPE
5
+ readonly isRetryable = false
6
+ readonly resourceType: string
7
+
2
8
  constructor(resourceType: string) {
3
9
  super(`Unexpected resource type "${resourceType}"`)
4
10
  this.name = 'UnexpectedResourceTypeError'
11
+ this.resourceType = resourceType
5
12
  }
6
13
  }
@@ -1,5 +1,5 @@
1
1
  import { getFileImportJob } from '../@api'
2
- import { PollingAbortedError } from '../@errors'
2
+ import { PollingAbortedError, PollingTimeoutError } from '../@errors'
3
3
  import type { FileImportJob } from '../@types'
4
4
  import { hasImportJobStartedProcessing } from './file-import-job-helpers'
5
5
 
@@ -64,9 +64,6 @@ export const pollJobUntilProcessing = async ({
64
64
  attempts++
65
65
  }
66
66
 
67
- throw new Error(
68
- `Job did not start processing after ${maxAttempts} attempts (${
69
- (maxAttempts * pollingInterval) / 1000
70
- }s)`
71
- )
67
+ const totalTimeSeconds = (maxAttempts * pollingInterval) / 1000
68
+ throw new PollingTimeoutError(maxAttempts, totalTimeSeconds)
72
69
  }
@@ -1,5 +1,5 @@
1
1
  import { getFileImportJob } from '../@api'
2
- import { PollingAbortedError } from '../@errors'
2
+ import { PollingAbortedError, PollingTimeoutError } from '../@errors'
3
3
  import type { FileImportJob } from '../@types'
4
4
  import { isImportJobTerminal } from './file-import-job-helpers'
5
5
 
@@ -68,9 +68,6 @@ export const pollJobUntilValidated = async ({
68
68
  attempts++
69
69
  }
70
70
 
71
- throw new Error(
72
- `Job validation timeout after ${maxAttempts} attempts (${
73
- (maxAttempts * pollingInterval) / 1000
74
- }s)`
75
- )
71
+ const totalTimeSeconds = (maxAttempts * pollingInterval) / 1000
72
+ throw new PollingTimeoutError(maxAttempts, totalTimeSeconds)
76
73
  }