@stack-spot/portal-network 0.184.0 → 0.185.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 (136) hide show
  1. package/CHANGELOG.md +2419 -2412
  2. package/dist/api/account.js +1 -1
  3. package/dist/api/agent-tools.js +1 -1
  4. package/dist/api/agent.js +1 -1
  5. package/dist/api/ai.js +1 -1
  6. package/dist/api/apiManagement.js +1 -1
  7. package/dist/api/apiRuntime.js +1 -1
  8. package/dist/api/cloudAccount.js +1 -1
  9. package/dist/api/cloudPlatform.js +1 -1
  10. package/dist/api/cloudPlatformHorizon.js +1 -1
  11. package/dist/api/cloudRuntimes.js +1 -1
  12. package/dist/api/cloudServices.js +1 -1
  13. package/dist/api/codeShift.d.ts +63 -4
  14. package/dist/api/codeShift.d.ts.map +1 -1
  15. package/dist/api/codeShift.js +14 -1
  16. package/dist/api/codeShift.js.map +1 -1
  17. package/dist/api/content.js +1 -1
  18. package/dist/api/dataIntegration.js +1 -1
  19. package/dist/api/discover.js +1 -1
  20. package/dist/api/genAiInference.js +1 -1
  21. package/dist/api/insights.js +1 -1
  22. package/dist/api/notification.js +1 -1
  23. package/dist/api/secrets.js +1 -1
  24. package/dist/api/serviceCatalog.js +1 -1
  25. package/dist/api/workspace-ai.js +1 -1
  26. package/dist/api/workspace.js +1 -1
  27. package/dist/api/workspaceManager.js +1 -1
  28. package/dist/api/workspaceSearchEngine.js +1 -1
  29. package/dist/client/code-shift.d.ts +22 -0
  30. package/dist/client/code-shift.d.ts.map +1 -1
  31. package/dist/client/code-shift.js +28 -1
  32. package/dist/client/code-shift.js.map +1 -1
  33. package/package.json +6 -6
  34. package/scripts/generate-apis.ts +134 -134
  35. package/src/api/account.ts +8367 -8367
  36. package/src/api/agent-tools.ts +2169 -2169
  37. package/src/api/agent.ts +1083 -1083
  38. package/src/api/ai.ts +3388 -3388
  39. package/src/api/apiManagement.ts +570 -570
  40. package/src/api/apiRuntime.ts +2103 -2103
  41. package/src/api/cloudAccount.ts +1239 -1239
  42. package/src/api/cloudPlatform.ts +927 -927
  43. package/src/api/cloudPlatformHorizon.ts +2655 -2655
  44. package/src/api/cloudRuntimes.ts +2043 -2043
  45. package/src/api/cloudServices.ts +1445 -1445
  46. package/src/api/codeShift.ts +3567 -3481
  47. package/src/api/content.ts +9785 -9785
  48. package/src/api/dataIntegration.ts +1657 -1657
  49. package/src/api/discover.ts +435 -435
  50. package/src/api/eventBus.ts +171 -171
  51. package/src/api/genAiInference.ts +603 -603
  52. package/src/api/insights.ts +310 -310
  53. package/src/api/notification.ts +334 -334
  54. package/src/api/secrets.ts +342 -342
  55. package/src/api/serviceCatalog.ts +2908 -2908
  56. package/src/api/workflows.ts +1669 -1669
  57. package/src/api/workspace-ai.ts +677 -677
  58. package/src/api/workspace.ts +5889 -5889
  59. package/src/api/workspaceManager.ts +2951 -2951
  60. package/src/api/workspaceSearchEngine.ts +153 -153
  61. package/src/api-addresses.ts +120 -120
  62. package/src/apis-itau.json +225 -225
  63. package/src/apis.json +225 -225
  64. package/src/client/account.ts +902 -902
  65. package/src/client/agent-tools.ts +210 -210
  66. package/src/client/agent.ts +81 -81
  67. package/src/client/ai.ts +395 -395
  68. package/src/client/api-management.ts +40 -40
  69. package/src/client/cloud-account.ts +70 -70
  70. package/src/client/cloud-platform-horizon.ts +113 -113
  71. package/src/client/cloud-platform.ts +163 -163
  72. package/src/client/cloud-runtimes.ts +129 -129
  73. package/src/client/cloud-services.ts +94 -94
  74. package/src/client/code-shift.ts +364 -349
  75. package/src/client/content.ts +538 -538
  76. package/src/client/data-integration.ts +191 -191
  77. package/src/client/discover.ts +89 -89
  78. package/src/client/event-bus.ts +84 -84
  79. package/src/client/gen-ai-inference.ts +65 -65
  80. package/src/client/insights.ts +28 -28
  81. package/src/client/notification.ts +32 -32
  82. package/src/client/runtime-manager.ts +76 -76
  83. package/src/client/secrets.ts +60 -60
  84. package/src/client/types.ts +377 -377
  85. package/src/client/workflow.ts +83 -83
  86. package/src/client/workspace-ai.ts +191 -191
  87. package/src/client/workspace-manager.ts +564 -564
  88. package/src/client/workspace-search.ts +39 -39
  89. package/src/client/workspace.ts +480 -480
  90. package/src/error/DefaultAPIError.ts +151 -151
  91. package/src/error/FileUploadError.ts +18 -18
  92. package/src/error/IgnoredErrorCodes.ts +3 -3
  93. package/src/error/StackspotAPIError.ts +101 -101
  94. package/src/error/StreamCanceledError.ts +10 -10
  95. package/src/error/StreamError.ts +7 -7
  96. package/src/error/StreamJsonError.ts +10 -10
  97. package/src/error/dictionary/account.ts +58 -58
  98. package/src/error/dictionary/action-details.ts +20 -20
  99. package/src/error/dictionary/action.ts +211 -211
  100. package/src/error/dictionary/agent-tools.ts +75 -75
  101. package/src/error/dictionary/ai-inference.ts +28 -28
  102. package/src/error/dictionary/base.ts +22 -22
  103. package/src/error/dictionary/cloud-platform.ts +82 -82
  104. package/src/error/dictionary/cnt-fields.ts +14 -14
  105. package/src/error/dictionary/cnt.ts +103 -103
  106. package/src/error/dictionary/code-shift.ts +12 -12
  107. package/src/error/dictionary/rte.ts +24 -24
  108. package/src/error/dictionary/rtm.ts +10 -10
  109. package/src/error/dictionary/secrets.ts +14 -14
  110. package/src/error/dictionary/workspace-ai.ts +10 -10
  111. package/src/error/dictionary/workspace-details.ts +15 -15
  112. package/src/error/dictionary/workspace-fields.ts +10 -10
  113. package/src/error/dictionary/workspace.ts +209 -209
  114. package/src/error/types.ts +21 -21
  115. package/src/index.ts +43 -43
  116. package/src/network/AutoInfiniteQuery.ts +115 -115
  117. package/src/network/AutoMutation.ts +27 -27
  118. package/src/network/AutoOperation.ts +73 -73
  119. package/src/network/AutoQuery.ts +75 -75
  120. package/src/network/ManualInfiniteQuery.ts +95 -95
  121. package/src/network/ManualMutation.ts +40 -40
  122. package/src/network/ManualOperation.ts +52 -52
  123. package/src/network/ManualQuery.ts +82 -82
  124. package/src/network/NetworkClient.ts +167 -167
  125. package/src/network/ReactQueryNetworkClient.ts +312 -312
  126. package/src/network/react-query-client.ts +14 -14
  127. package/src/network/types.ts +294 -294
  128. package/src/types.ts +1 -1
  129. package/src/utils/StreamedArray.tsx +146 -146
  130. package/src/utils/StreamedJson.tsx +166 -166
  131. package/src/utils/remove-authorization-param.ts +6 -6
  132. package/src/utils/string.ts +19 -19
  133. package/src/utils/use-extended-list.ts +80 -80
  134. package/src/utils/use-streamed-array.ts +17 -17
  135. package/tsconfig.build.json +4 -4
  136. package/tsconfig.json +10 -10
@@ -1,151 +1,151 @@
1
- import { Dictionary } from '@stack-spot/portal-translate'
2
- import { every, isString } from 'lodash'
3
- import { actionDetails } from './dictionary/action-details'
4
- import { baseDictionary } from './dictionary/base'
5
- import { cntFields } from './dictionary/cnt-fields'
6
- import { workspaceDetails } from './dictionary/workspace-details'
7
- import { workspaceFields } from './dictionary/workspace-fields'
8
- import { ignoredTitleErrorCodes } from './IgnoredErrorCodes'
9
- import { ErrorDetailsProperties, StackspotAPIError } from './StackspotAPIError'
10
- import { ErrorResponse, LanguageSuggestedMessageKeys, ValidationDetails } from './types'
11
-
12
- // these details don't say anything the status already doesn't and we'd better use local translations for them.
13
- const ignoredDescriptions = [
14
- 'internal server error', 'not found', 'gateway timeout', 'temporally unavailable', 'forbidden', 'unauthorized', 'bad request',
15
- ]
16
-
17
- const fieldDictionary = {
18
- cnt: cntFields,
19
- wks: workspaceFields,
20
- }
21
-
22
- const detailsDictionary = {
23
- wks: workspaceDetails,
24
- actionapi: actionDetails,
25
- }
26
-
27
- function getTitle(status: number, raw: ErrorResponse, dictionary: Dictionary, language: 'pt' | 'en') {
28
- if (ignoredTitleErrorCodes.includes(raw.code)) return ' '
29
- if (dictionary[language][raw.code]) return dictionary[language][raw.code]
30
- if (raw.details && !ignoredDescriptions.includes(raw.details)) return raw.details
31
- return (baseDictionary as Dictionary)[language][status] || baseDictionary[language].defaultTitle
32
- }
33
-
34
- function getValues(detail: ValidationDetails) {
35
- return detail.values && every(detail.values, isString) ? `\n${detail.values.join('\n')}` : ''
36
- }
37
-
38
- function getSuggestedMessages(suggestedMessage: ErrorResponse['suggestedMessages'] | null | undefined, language?: 'pt' | 'en') {
39
- const parseLanguage: Record<'pt' | 'en', LanguageSuggestedMessageKeys> = { pt: 'ptBr', en: 'enUs' }
40
- return suggestedMessage?.[parseLanguage?.[language || 'en']]
41
- }
42
-
43
- const UNIT_REGEX_TEMPLATE = /{\d}/g
44
- const RANGE_REGEX_TEMPLATE = /{1-n}/g
45
-
46
- function containsNumberInBraces(input: string) {
47
- return UNIT_REGEX_TEMPLATE.test(input) || RANGE_REGEX_TEMPLATE.test(input)
48
- }
49
-
50
- export function interpolateErrors(message: string, values: string[], fieldValuesFileContent: Record<string, string>) {
51
- return message
52
- .replace(UNIT_REGEX_TEMPLATE, (value) => {
53
- const position = +value.replace(/{|}/g, '')
54
- const index = position - 1
55
-
56
- const fieldValue = values[index]
57
- return fieldValuesFileContent[fieldValue] || fieldValue
58
- })
59
- .replace(RANGE_REGEX_TEMPLATE, () => values.toString())
60
- }
61
-
62
-
63
- function createMessage(status: number, raw: ErrorResponse, dictionary: Dictionary, language?: 'pt' | 'en'): ErrorDetailsProperties {
64
- const title = getTitle(status, raw, dictionary, language || 'en')
65
- const api = raw.code?.split(/[-_]/)[0]
66
- const dictDetails = (detailsDictionary[api?.toLowerCase() as keyof typeof detailsDictionary] ?? {})[language || 'en']
67
- const dictionaryDetails = raw.code && dictDetails ? dictDetails[raw.code] : {}
68
-
69
- if (raw?.validationDetails?.length) {
70
-
71
- const suggestedMessages = raw.validationDetails.map((detail) =>
72
- getSuggestedMessages(detail?.suggestedMessages, language)).filter((msg) => !!msg)
73
-
74
- if (suggestedMessages.length) {
75
- return { description: suggestedMessages.join('\n'), ...dictionaryDetails }
76
- }
77
-
78
- const details = raw.validationDetails?.map((detail) => {
79
- const dict: Record<string, string> =
80
- (fieldDictionary[api?.toLowerCase() as keyof typeof fieldDictionary] ?? {})[language || 'en'] ?? {}
81
- const codeTranslatedMessage = raw.code !== detail.code && dictionary[language || 'en'][detail.code]
82
-
83
- if (codeTranslatedMessage && containsNumberInBraces(codeTranslatedMessage) && (detail.values?.length || detail.field?.length)) {
84
- const value = detail.values?.length ? detail.values : (detail.field ? [detail.field] : [])
85
- return interpolateErrors(codeTranslatedMessage, value, dict)
86
- }
87
-
88
- const name = dict[detail.code] || detail.field || codeTranslatedMessage || detail.details || ''
89
- return `${name}${getValues(detail)}`
90
- })?.filter(d => !!d)
91
- return { description: details ? `${title}\n${details?.join('\n')}` : title, ...dictionaryDetails }
92
- }
93
-
94
- if (raw?.suggestedMessages) {
95
- const suggestedMessages = getSuggestedMessages(raw?.suggestedMessages, language)
96
- if (suggestedMessages) {
97
- return { description: suggestedMessages, ...dictionaryDetails }
98
- }
99
- }
100
-
101
- return { description: title, ...dictionaryDetails }
102
- }
103
-
104
- /**
105
- * This represents the Error thrown by most Stackspot APIs.
106
- */
107
- export class DefaultAPIError extends StackspotAPIError {
108
- /**
109
- * The error object as defined by the Stackspot API. If the response doesn't match the expected format this will be undefined.
110
- */
111
- data?: ErrorResponse
112
- /**
113
- * The response data, if this matches the expected format expected by a Stackspot Error, it will be the same as `data`.
114
- */
115
- raw?: any
116
-
117
- constructor(
118
- /**
119
- * The response's data
120
- */
121
- rawResponse: any,
122
- /**
123
- * The response's status
124
- */
125
- status: number,
126
- /**
127
- * A dictionary for translating error codes and descriptions.
128
- */
129
- dictionary: Dictionary,
130
- /**
131
- * The response's headers.
132
- */
133
- headers?: Headers,
134
- ) {
135
- let parsedResponse
136
- try {
137
- parsedResponse = JSON.parse(rawResponse)
138
- } catch (error) {
139
- parsedResponse = rawResponse
140
- }
141
-
142
- super({
143
- status: status,
144
- code: parsedResponse.code,
145
- message: language => createMessage(status, parsedResponse, dictionary, language),
146
- headers,
147
- })
148
- this.raw = parsedResponse
149
- if (this.raw?.code !== undefined && this.raw?.status !== undefined && this.raw?.details !== undefined) this.data = parsedResponse
150
- }
151
- }
1
+ import { Dictionary } from '@stack-spot/portal-translate'
2
+ import { every, isString } from 'lodash'
3
+ import { actionDetails } from './dictionary/action-details'
4
+ import { baseDictionary } from './dictionary/base'
5
+ import { cntFields } from './dictionary/cnt-fields'
6
+ import { workspaceDetails } from './dictionary/workspace-details'
7
+ import { workspaceFields } from './dictionary/workspace-fields'
8
+ import { ignoredTitleErrorCodes } from './IgnoredErrorCodes'
9
+ import { ErrorDetailsProperties, StackspotAPIError } from './StackspotAPIError'
10
+ import { ErrorResponse, LanguageSuggestedMessageKeys, ValidationDetails } from './types'
11
+
12
+ // these details don't say anything the status already doesn't and we'd better use local translations for them.
13
+ const ignoredDescriptions = [
14
+ 'internal server error', 'not found', 'gateway timeout', 'temporally unavailable', 'forbidden', 'unauthorized', 'bad request',
15
+ ]
16
+
17
+ const fieldDictionary = {
18
+ cnt: cntFields,
19
+ wks: workspaceFields,
20
+ }
21
+
22
+ const detailsDictionary = {
23
+ wks: workspaceDetails,
24
+ actionapi: actionDetails,
25
+ }
26
+
27
+ function getTitle(status: number, raw: ErrorResponse, dictionary: Dictionary, language: 'pt' | 'en') {
28
+ if (ignoredTitleErrorCodes.includes(raw.code)) return ' '
29
+ if (dictionary[language][raw.code]) return dictionary[language][raw.code]
30
+ if (raw.details && !ignoredDescriptions.includes(raw.details)) return raw.details
31
+ return (baseDictionary as Dictionary)[language][status] || baseDictionary[language].defaultTitle
32
+ }
33
+
34
+ function getValues(detail: ValidationDetails) {
35
+ return detail.values && every(detail.values, isString) ? `\n${detail.values.join('\n')}` : ''
36
+ }
37
+
38
+ function getSuggestedMessages(suggestedMessage: ErrorResponse['suggestedMessages'] | null | undefined, language?: 'pt' | 'en') {
39
+ const parseLanguage: Record<'pt' | 'en', LanguageSuggestedMessageKeys> = { pt: 'ptBr', en: 'enUs' }
40
+ return suggestedMessage?.[parseLanguage?.[language || 'en']]
41
+ }
42
+
43
+ const UNIT_REGEX_TEMPLATE = /{\d}/g
44
+ const RANGE_REGEX_TEMPLATE = /{1-n}/g
45
+
46
+ function containsNumberInBraces(input: string) {
47
+ return UNIT_REGEX_TEMPLATE.test(input) || RANGE_REGEX_TEMPLATE.test(input)
48
+ }
49
+
50
+ export function interpolateErrors(message: string, values: string[], fieldValuesFileContent: Record<string, string>) {
51
+ return message
52
+ .replace(UNIT_REGEX_TEMPLATE, (value) => {
53
+ const position = +value.replace(/{|}/g, '')
54
+ const index = position - 1
55
+
56
+ const fieldValue = values[index]
57
+ return fieldValuesFileContent[fieldValue] || fieldValue
58
+ })
59
+ .replace(RANGE_REGEX_TEMPLATE, () => values.toString())
60
+ }
61
+
62
+
63
+ function createMessage(status: number, raw: ErrorResponse, dictionary: Dictionary, language?: 'pt' | 'en'): ErrorDetailsProperties {
64
+ const title = getTitle(status, raw, dictionary, language || 'en')
65
+ const api = raw.code?.split(/[-_]/)[0]
66
+ const dictDetails = (detailsDictionary[api?.toLowerCase() as keyof typeof detailsDictionary] ?? {})[language || 'en']
67
+ const dictionaryDetails = raw.code && dictDetails ? dictDetails[raw.code] : {}
68
+
69
+ if (raw?.validationDetails?.length) {
70
+
71
+ const suggestedMessages = raw.validationDetails.map((detail) =>
72
+ getSuggestedMessages(detail?.suggestedMessages, language)).filter((msg) => !!msg)
73
+
74
+ if (suggestedMessages.length) {
75
+ return { description: suggestedMessages.join('\n'), ...dictionaryDetails }
76
+ }
77
+
78
+ const details = raw.validationDetails?.map((detail) => {
79
+ const dict: Record<string, string> =
80
+ (fieldDictionary[api?.toLowerCase() as keyof typeof fieldDictionary] ?? {})[language || 'en'] ?? {}
81
+ const codeTranslatedMessage = raw.code !== detail.code && dictionary[language || 'en'][detail.code]
82
+
83
+ if (codeTranslatedMessage && containsNumberInBraces(codeTranslatedMessage) && (detail.values?.length || detail.field?.length)) {
84
+ const value = detail.values?.length ? detail.values : (detail.field ? [detail.field] : [])
85
+ return interpolateErrors(codeTranslatedMessage, value, dict)
86
+ }
87
+
88
+ const name = dict[detail.code] || detail.field || codeTranslatedMessage || detail.details || ''
89
+ return `${name}${getValues(detail)}`
90
+ })?.filter(d => !!d)
91
+ return { description: details ? `${title}\n${details?.join('\n')}` : title, ...dictionaryDetails }
92
+ }
93
+
94
+ if (raw?.suggestedMessages) {
95
+ const suggestedMessages = getSuggestedMessages(raw?.suggestedMessages, language)
96
+ if (suggestedMessages) {
97
+ return { description: suggestedMessages, ...dictionaryDetails }
98
+ }
99
+ }
100
+
101
+ return { description: title, ...dictionaryDetails }
102
+ }
103
+
104
+ /**
105
+ * This represents the Error thrown by most Stackspot APIs.
106
+ */
107
+ export class DefaultAPIError extends StackspotAPIError {
108
+ /**
109
+ * The error object as defined by the Stackspot API. If the response doesn't match the expected format this will be undefined.
110
+ */
111
+ data?: ErrorResponse
112
+ /**
113
+ * The response data, if this matches the expected format expected by a Stackspot Error, it will be the same as `data`.
114
+ */
115
+ raw?: any
116
+
117
+ constructor(
118
+ /**
119
+ * The response's data
120
+ */
121
+ rawResponse: any,
122
+ /**
123
+ * The response's status
124
+ */
125
+ status: number,
126
+ /**
127
+ * A dictionary for translating error codes and descriptions.
128
+ */
129
+ dictionary: Dictionary,
130
+ /**
131
+ * The response's headers.
132
+ */
133
+ headers?: Headers,
134
+ ) {
135
+ let parsedResponse
136
+ try {
137
+ parsedResponse = JSON.parse(rawResponse)
138
+ } catch (error) {
139
+ parsedResponse = rawResponse
140
+ }
141
+
142
+ super({
143
+ status: status,
144
+ code: parsedResponse.code,
145
+ message: language => createMessage(status, parsedResponse, dictionary, language),
146
+ headers,
147
+ })
148
+ this.raw = parsedResponse
149
+ if (this.raw?.code !== undefined && this.raw?.status !== undefined && this.raw?.details !== undefined) this.data = parsedResponse
150
+ }
151
+ }
@@ -1,18 +1,18 @@
1
- import { HttpValidationError } from '../api/ai'
2
- import { StackspotAPIError } from './StackspotAPIError'
3
-
4
- export class FileUploadError extends StackspotAPIError {
5
- readonly fileName: string
6
-
7
- constructor(fileName: string, error: any) {
8
- super({
9
- status: error.status,
10
- headers: error.headers,
11
- stack: error.stack,
12
- message: error instanceof StackspotAPIError
13
- ? error.message
14
- : (error.data as HttpValidationError | undefined)?.detail?.map(d => d.msg)?.join('\n'),
15
- })
16
- this.fileName = fileName
17
- }
18
- }
1
+ import { HttpValidationError } from '../api/ai'
2
+ import { StackspotAPIError } from './StackspotAPIError'
3
+
4
+ export class FileUploadError extends StackspotAPIError {
5
+ readonly fileName: string
6
+
7
+ constructor(fileName: string, error: any) {
8
+ super({
9
+ status: error.status,
10
+ headers: error.headers,
11
+ stack: error.stack,
12
+ message: error instanceof StackspotAPIError
13
+ ? error.message
14
+ : (error.data as HttpValidationError | undefined)?.detail?.map(d => d.msg)?.join('\n'),
15
+ })
16
+ this.fileName = fileName
17
+ }
18
+ }
@@ -1,3 +1,3 @@
1
-
2
- // A list o errors we would not like to render on screen as title messages.
3
- export const ignoredTitleErrorCodes = ['WKS_CONTEXT_ATTRIBUTE_TYPE_ERROR']
1
+
2
+ // A list o errors we would not like to render on screen as title messages.
3
+ export const ignoredTitleErrorCodes = ['WKS_CONTEXT_ATTRIBUTE_TYPE_ERROR']
@@ -1,101 +1,101 @@
1
- import { getLanguage, ptEn } from '@stack-spot/portal-translate'
2
-
3
- export type InternationalizedMessage = (language: 'pt' | 'en') => string | ErrorDetailsProperties
4
-
5
- export interface ErrorDetailsProperties {
6
- /**
7
- * The error title
8
- */
9
- title?: string,
10
- /**
11
- * The error description
12
- */
13
- description?: string,
14
- /**
15
- * Label for link
16
- */
17
- linkLabel?: string,
18
- /**
19
- * Text for href of link
20
- */
21
- linkHref?: string,
22
- }
23
-
24
- interface ErrorProperties {
25
- /**
26
- * The response's status.
27
- */
28
- status: number,
29
- /**
30
- * The response's headers.
31
- */
32
- headers?: Headers,
33
- /**
34
- * The error code defined by the API, if any.
35
- */
36
- code?: string,
37
- /**
38
- * The error message: may be a simple string or a function that returns a string depending on the language passed as parameter.
39
- *
40
- * If not provided, will attempt to use the error code or 'unknown'.
41
- */
42
- message?: InternationalizedMessage | string | ErrorDetailsProperties,
43
- /**
44
- * The error's stack trace, if any.
45
- */
46
- stack?: string,
47
-
48
- }
49
-
50
- function getMessage(error: ErrorProperties['message']) {
51
- const message = typeof error === 'function' ? error('en') : error
52
- return typeof message === 'string' ? message : message?.description
53
- }
54
-
55
- export class StackspotAPIError extends Error {
56
- /**
57
- * The response's status.
58
- */
59
- status: number
60
- /**
61
- * The response's headers.
62
- */
63
- headers: Headers | undefined
64
- /**
65
- * The error code defined by the API, if any.
66
- */
67
- code: string | undefined
68
- private intl?: InternationalizedMessage
69
-
70
- constructor({ status, code, headers, message, stack }: ErrorProperties) {
71
- super(`Stackspot API error (network ${status}): ${getMessage(message)}`)
72
- this.status = status
73
- this.code = code
74
- this.headers = headers
75
- this.stack = stack
76
- this.intl = typeof message === 'string' || typeof message === 'object' ? () => message : message
77
- }
78
-
79
- /**
80
- * Translates the error to the given language.
81
- * @param language
82
- * @returns an error message
83
- */
84
- translate(language = getLanguage(ptEn)): string {
85
- const unknown = language === 'en' ? 'unknown error' : 'erro desconhecido'
86
-
87
- const error = this.intl?.(language)
88
- const message = typeof error === 'string' ? error : error?.description
89
- return message ?? this.message ?? this.code ?? (this.status === 0 ? unknown : `${this.status}`)
90
- }
91
-
92
- translateDetails(language = getLanguage(ptEn)): ErrorDetailsProperties {
93
- const unknown = language === 'en' ? 'unknown error' : 'erro desconhecido'
94
- const errorMessage = this.intl?.(language)
95
- if (typeof errorMessage === 'string')
96
- return { description: errorMessage }
97
- if (typeof errorMessage === 'object')
98
- return errorMessage
99
- return { description: this.message ?? this.code ?? (this.status === 0 ? unknown : `${this.status}`) }
100
- }
101
- }
1
+ import { getLanguage, ptEn } from '@stack-spot/portal-translate'
2
+
3
+ export type InternationalizedMessage = (language: 'pt' | 'en') => string | ErrorDetailsProperties
4
+
5
+ export interface ErrorDetailsProperties {
6
+ /**
7
+ * The error title
8
+ */
9
+ title?: string,
10
+ /**
11
+ * The error description
12
+ */
13
+ description?: string,
14
+ /**
15
+ * Label for link
16
+ */
17
+ linkLabel?: string,
18
+ /**
19
+ * Text for href of link
20
+ */
21
+ linkHref?: string,
22
+ }
23
+
24
+ interface ErrorProperties {
25
+ /**
26
+ * The response's status.
27
+ */
28
+ status: number,
29
+ /**
30
+ * The response's headers.
31
+ */
32
+ headers?: Headers,
33
+ /**
34
+ * The error code defined by the API, if any.
35
+ */
36
+ code?: string,
37
+ /**
38
+ * The error message: may be a simple string or a function that returns a string depending on the language passed as parameter.
39
+ *
40
+ * If not provided, will attempt to use the error code or 'unknown'.
41
+ */
42
+ message?: InternationalizedMessage | string | ErrorDetailsProperties,
43
+ /**
44
+ * The error's stack trace, if any.
45
+ */
46
+ stack?: string,
47
+
48
+ }
49
+
50
+ function getMessage(error: ErrorProperties['message']) {
51
+ const message = typeof error === 'function' ? error('en') : error
52
+ return typeof message === 'string' ? message : message?.description
53
+ }
54
+
55
+ export class StackspotAPIError extends Error {
56
+ /**
57
+ * The response's status.
58
+ */
59
+ status: number
60
+ /**
61
+ * The response's headers.
62
+ */
63
+ headers: Headers | undefined
64
+ /**
65
+ * The error code defined by the API, if any.
66
+ */
67
+ code: string | undefined
68
+ private intl?: InternationalizedMessage
69
+
70
+ constructor({ status, code, headers, message, stack }: ErrorProperties) {
71
+ super(`Stackspot API error (network ${status}): ${getMessage(message)}`)
72
+ this.status = status
73
+ this.code = code
74
+ this.headers = headers
75
+ this.stack = stack
76
+ this.intl = typeof message === 'string' || typeof message === 'object' ? () => message : message
77
+ }
78
+
79
+ /**
80
+ * Translates the error to the given language.
81
+ * @param language
82
+ * @returns an error message
83
+ */
84
+ translate(language = getLanguage(ptEn)): string {
85
+ const unknown = language === 'en' ? 'unknown error' : 'erro desconhecido'
86
+
87
+ const error = this.intl?.(language)
88
+ const message = typeof error === 'string' ? error : error?.description
89
+ return message ?? this.message ?? this.code ?? (this.status === 0 ? unknown : `${this.status}`)
90
+ }
91
+
92
+ translateDetails(language = getLanguage(ptEn)): ErrorDetailsProperties {
93
+ const unknown = language === 'en' ? 'unknown error' : 'erro desconhecido'
94
+ const errorMessage = this.intl?.(language)
95
+ if (typeof errorMessage === 'string')
96
+ return { description: errorMessage }
97
+ if (typeof errorMessage === 'object')
98
+ return errorMessage
99
+ return { description: this.message ?? this.code ?? (this.status === 0 ? unknown : `${this.status}`) }
100
+ }
101
+ }
@@ -1,10 +1,10 @@
1
- import { StreamError } from './StreamError'
2
-
3
- export class StreamCanceledError extends StreamError {
4
- constructor() {
5
- super(language => language === 'pt'
6
- ? 'Erro: a mensagem foi abortada pelo usuário.'
7
- : 'Error: the message was aborted by the user.',
8
- )
9
- }
10
- }
1
+ import { StreamError } from './StreamError'
2
+
3
+ export class StreamCanceledError extends StreamError {
4
+ constructor() {
5
+ super(language => language === 'pt'
6
+ ? 'Erro: a mensagem foi abortada pelo usuário.'
7
+ : 'Error: the message was aborted by the user.',
8
+ )
9
+ }
10
+ }
@@ -1,7 +1,7 @@
1
- import { InternationalizedMessage, StackspotAPIError } from './StackspotAPIError'
2
-
3
- export class StreamError extends StackspotAPIError {
4
- constructor(message: InternationalizedMessage) {
5
- super({ status: 0, message })
6
- }
7
- }
1
+ import { InternationalizedMessage, StackspotAPIError } from './StackspotAPIError'
2
+
3
+ export class StreamError extends StackspotAPIError {
4
+ constructor(message: InternationalizedMessage) {
5
+ super({ status: 0, message })
6
+ }
7
+ }
@@ -1,10 +1,10 @@
1
- import { StreamError } from './StreamError'
2
-
3
- export class StreamJsonError extends StreamError {
4
- constructor() {
5
- super(language => language === 'pt'
6
- ? 'Erro no formato do stream. O conteúdo não é um JSON válido.'
7
- : 'Stream format error. The streamed content is not a valid JSON.',
8
- )
9
- }
10
- }
1
+ import { StreamError } from './StreamError'
2
+
3
+ export class StreamJsonError extends StreamError {
4
+ constructor() {
5
+ super(language => language === 'pt'
6
+ ? 'Erro no formato do stream. O conteúdo não é um JSON válido.'
7
+ : 'Stream format error. The streamed content is not a valid JSON.',
8
+ )
9
+ }
10
+ }