@stack-spot/portal-network 0.160.1 → 0.162.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 (135) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/api/codeShift.d.ts +143 -205
  3. package/dist/api/codeShift.d.ts.map +1 -1
  4. package/dist/api/codeShift.js +50 -94
  5. package/dist/api/codeShift.js.map +1 -1
  6. package/dist/api-addresses.d.ts +30 -0
  7. package/dist/api-addresses.d.ts.map +1 -1
  8. package/dist/api-addresses.js +57 -3
  9. package/dist/api-addresses.js.map +1 -1
  10. package/dist/client/account.d.ts.map +1 -1
  11. package/dist/client/account.js +2 -2
  12. package/dist/client/account.js.map +1 -1
  13. package/dist/client/agent-tools.d.ts.map +1 -1
  14. package/dist/client/agent-tools.js +2 -2
  15. package/dist/client/agent-tools.js.map +1 -1
  16. package/dist/client/agent.d.ts +1 -0
  17. package/dist/client/agent.d.ts.map +1 -1
  18. package/dist/client/agent.js +3 -2
  19. package/dist/client/agent.js.map +1 -1
  20. package/dist/client/ai.d.ts.map +1 -1
  21. package/dist/client/ai.js +2 -2
  22. package/dist/client/ai.js.map +1 -1
  23. package/dist/client/api-management.d.ts.map +1 -1
  24. package/dist/client/api-management.js +2 -2
  25. package/dist/client/api-management.js.map +1 -1
  26. package/dist/client/cloud-account.d.ts.map +1 -1
  27. package/dist/client/cloud-account.js +2 -2
  28. package/dist/client/cloud-account.js.map +1 -1
  29. package/dist/client/cloud-platform-horizon.d.ts.map +1 -1
  30. package/dist/client/cloud-platform-horizon.js +2 -2
  31. package/dist/client/cloud-platform-horizon.js.map +1 -1
  32. package/dist/client/cloud-platform.d.ts.map +1 -1
  33. package/dist/client/cloud-platform.js +2 -2
  34. package/dist/client/cloud-platform.js.map +1 -1
  35. package/dist/client/cloud-runtimes.d.ts.map +1 -1
  36. package/dist/client/cloud-runtimes.js +2 -2
  37. package/dist/client/cloud-runtimes.js.map +1 -1
  38. package/dist/client/cloud-services.d.ts.map +1 -1
  39. package/dist/client/cloud-services.js +2 -2
  40. package/dist/client/cloud-services.js.map +1 -1
  41. package/dist/client/code-shift.d.ts +32 -67
  42. package/dist/client/code-shift.d.ts.map +1 -1
  43. package/dist/client/code-shift.js +41 -75
  44. package/dist/client/code-shift.js.map +1 -1
  45. package/dist/client/content.d.ts.map +1 -1
  46. package/dist/client/content.js +2 -2
  47. package/dist/client/content.js.map +1 -1
  48. package/dist/client/data-integration.d.ts.map +1 -1
  49. package/dist/client/data-integration.js +2 -2
  50. package/dist/client/data-integration.js.map +1 -1
  51. package/dist/client/discovery.d.ts.map +1 -1
  52. package/dist/client/discovery.js +2 -2
  53. package/dist/client/discovery.js.map +1 -1
  54. package/dist/client/event-bus.d.ts.map +1 -1
  55. package/dist/client/event-bus.js +2 -2
  56. package/dist/client/event-bus.js.map +1 -1
  57. package/dist/client/gen-ai-inference.d.ts.map +1 -1
  58. package/dist/client/gen-ai-inference.js +2 -2
  59. package/dist/client/gen-ai-inference.js.map +1 -1
  60. package/dist/client/insights.d.ts.map +1 -1
  61. package/dist/client/insights.js +2 -2
  62. package/dist/client/insights.js.map +1 -1
  63. package/dist/client/notification.d.ts.map +1 -1
  64. package/dist/client/notification.js +2 -2
  65. package/dist/client/notification.js.map +1 -1
  66. package/dist/client/runtime-manager.d.ts.map +1 -1
  67. package/dist/client/runtime-manager.js +2 -2
  68. package/dist/client/runtime-manager.js.map +1 -1
  69. package/dist/client/secrets.d.ts.map +1 -1
  70. package/dist/client/secrets.js +2 -2
  71. package/dist/client/secrets.js.map +1 -1
  72. package/dist/client/workflow.d.ts.map +1 -1
  73. package/dist/client/workflow.js +2 -2
  74. package/dist/client/workflow.js.map +1 -1
  75. package/dist/client/workspace-ai.d.ts +1 -4
  76. package/dist/client/workspace-ai.d.ts.map +1 -1
  77. package/dist/client/workspace-ai.js +2 -2
  78. package/dist/client/workspace-ai.js.map +1 -1
  79. package/dist/client/workspace-manager.d.ts.map +1 -1
  80. package/dist/client/workspace-manager.js +2 -2
  81. package/dist/client/workspace-manager.js.map +1 -1
  82. package/dist/client/workspace-search.d.ts.map +1 -1
  83. package/dist/client/workspace-search.js +2 -2
  84. package/dist/client/workspace-search.js.map +1 -1
  85. package/dist/client/workspace.d.ts.map +1 -1
  86. package/dist/client/workspace.js +2 -2
  87. package/dist/client/workspace.js.map +1 -1
  88. package/dist/error/DefaultAPIError.d.ts +1 -1
  89. package/dist/error/DefaultAPIError.d.ts.map +1 -1
  90. package/dist/error/DefaultAPIError.js +27 -12
  91. package/dist/error/DefaultAPIError.js.map +1 -1
  92. package/dist/error/types.d.ts +19 -0
  93. package/dist/error/types.d.ts.map +1 -0
  94. package/dist/error/types.js +2 -0
  95. package/dist/error/types.js.map +1 -0
  96. package/dist/index.d.ts +1 -1
  97. package/dist/index.d.ts.map +1 -1
  98. package/dist/index.js +1 -1
  99. package/dist/index.js.map +1 -1
  100. package/dist/network/NetworkClient.d.ts +6 -0
  101. package/dist/network/NetworkClient.d.ts.map +1 -1
  102. package/dist/network/NetworkClient.js +10 -1
  103. package/dist/network/NetworkClient.js.map +1 -1
  104. package/package.json +1 -1
  105. package/src/api/codeShift.ts +319 -490
  106. package/src/api-addresses.ts +75 -5
  107. package/src/client/account.ts +2 -2
  108. package/src/client/agent-tools.ts +2 -2
  109. package/src/client/agent.ts +4 -2
  110. package/src/client/ai.ts +2 -2
  111. package/src/client/api-management.ts +2 -2
  112. package/src/client/cloud-account.ts +2 -2
  113. package/src/client/cloud-platform-horizon.ts +2 -2
  114. package/src/client/cloud-platform.ts +2 -2
  115. package/src/client/cloud-runtimes.ts +2 -2
  116. package/src/client/cloud-services.ts +2 -2
  117. package/src/client/code-shift.ts +26 -59
  118. package/src/client/content.ts +2 -2
  119. package/src/client/data-integration.ts +2 -2
  120. package/src/client/discovery.ts +2 -2
  121. package/src/client/event-bus.ts +2 -2
  122. package/src/client/gen-ai-inference.ts +2 -2
  123. package/src/client/insights.ts +2 -2
  124. package/src/client/notification.ts +2 -2
  125. package/src/client/runtime-manager.ts +2 -2
  126. package/src/client/secrets.ts +2 -2
  127. package/src/client/workflow.ts +2 -2
  128. package/src/client/workspace-ai.ts +2 -2
  129. package/src/client/workspace-manager.ts +2 -2
  130. package/src/client/workspace-search.ts +2 -2
  131. package/src/client/workspace.ts +2 -2
  132. package/src/error/DefaultAPIError.ts +35 -12
  133. package/src/error/types.ts +21 -0
  134. package/src/index.ts +1 -1
  135. package/src/network/NetworkClient.ts +11 -1
@@ -1,14 +1,14 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
2
  import { defaults, getAppInfo, getAppsInRealm, getPluginDeployments, getRunByUlid, getRunsOnAllEnvs, getRunsOnEnv, getRunsRunning, getRunTaskPlugins, getRunTasks, runRollbackApp1, runRollbackInfra1 } from '../api/apiRuntime'
3
- import apis from '../apis.json'
4
3
  import { DefaultAPIError } from '../error/DefaultAPIError'
5
4
  import { rteDictionary } from '../error/dictionary/rte'
6
5
  import { StackspotAPIError } from '../error/StackspotAPIError'
7
6
  import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
7
+ import { getApiAddresses } from '../api-addresses'
8
8
 
9
9
  class RuntimeManagerClient extends ReactQueryNetworkClient {
10
10
  constructor() {
11
- super(apis.apiRuntime.url, defaults)
11
+ super(getApiAddresses().apiRuntime.url, defaults)
12
12
  }
13
13
 
14
14
  protected buildStackSpotError(error: HttpError): StackspotAPIError {
@@ -1,15 +1,15 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
2
 
3
3
  import { createKey, defaults, deleteKey, deleteSecretValue, editKey, encrypt, getAll1, getAvailability, updateSecretValue } from '../api/secrets'
4
- import apis from '../apis.json'
5
4
  import { DefaultAPIError } from '../error/DefaultAPIError'
6
5
  import { secretsDictionary } from '../error/dictionary/secrets'
7
6
  import { StackspotAPIError } from '../error/StackspotAPIError'
8
7
  import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
8
+ import { getApiAddresses } from '../api-addresses'
9
9
 
10
10
  class SecretClient extends ReactQueryNetworkClient {
11
11
  constructor() {
12
- super(apis.secrets.url, defaults)
12
+ super(getApiAddresses().secrets.url, defaults)
13
13
  }
14
14
 
15
15
  protected buildStackSpotError(error: HttpError): StackspotAPIError {
@@ -1,15 +1,15 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
2
  import { createApiServiceWorkflowsCreateApiDispatchPost, defaults, getExecutionDispatchRequestServiceWorkflowsExecutionIdRequestGet, getExecutionStatusServiceWorkflowsExecutionStatusExecutionIdGet, healthCheckServiceWorkflowsHealthCheckDispatchPost, runActionServiceWorkflowsRunActionDispatchPost, v1AcceptWorkflowExecutionJobSuspendedServiceV1ExecutionsExecutionIdJobsJobIdAcceptPost, v1GetWorkflowExecutionAttemptsV1ExecutionsExecutionIdAttemptsGet, v1GetWorkflowExecutionJobDetailServiceV1ExecutionsExecutionIdJobsJobIdGet, v1GetWorkflowExecutionJobGraphServiceV1ExecutionsExecutionIdGet, v1RefuseWorkflowExecutionJobSuspendedServiceV1ExecutionsExecutionIdJobsJobIdRefusePost, v1RetryWorkflowExecutionV1ExecutionsExecutionIdRetryPost } from '../api/workflows'
3
- import apis from '../apis.json'
4
3
  import { DefaultAPIError } from '../error/DefaultAPIError'
5
4
  import { actionDictionary } from '../error/dictionary/action'
6
5
  import { StackspotAPIError } from '../error/StackspotAPIError'
7
6
  import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
8
7
  import { removeAuthorizationParam } from '../utils/remove-authorization-param'
8
+ import { getApiAddresses } from '../api-addresses'
9
9
 
10
10
  class WorkflowClient extends ReactQueryNetworkClient {
11
11
  constructor() {
12
- super(apis.workflows.url, defaults)
12
+ super(getApiAddresses().workflows.url, defaults)
13
13
  }
14
14
 
15
15
  protected buildStackSpotError(error: HttpError): StackspotAPIError {
@@ -22,15 +22,15 @@ import {
22
22
  updateWorkspaceV1WorkspacesWorkspaceIdPatch,
23
23
  useShareableLinkV1ShareShareIdPatch,
24
24
  } from '../api/workspace-ai'
25
- import apis from '../apis.json'
26
25
  import { StackspotAPIError } from '../error/StackspotAPIError'
27
26
  import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
28
27
  import { removeAuthorizationParam } from '../utils/remove-authorization-param'
29
28
  import { FixedAddResourceToWorkspaceAi, FixedWorkspaceAiPermissions, ReplaceResult } from './types'
29
+ import { getApiAddresses } from '../api-addresses'
30
30
 
31
31
  class WorkspaceAiClient extends ReactQueryNetworkClient {
32
32
  constructor() {
33
- super(apis['workspace-ai'].url, defaults)
33
+ super(getApiAddresses()['workspace-ai'].url, defaults)
34
34
  }
35
35
 
36
36
  protected buildStackSpotError(error: HttpError): StackspotAPIError {
@@ -72,7 +72,6 @@ import {
72
72
  workspaceVariableControllerfindByName,
73
73
  workspaceVariableControllerupsert,
74
74
  } from '../api/workspaceManager'
75
- import apis from '../apis.json'
76
75
  import { DefaultAPIError } from '../error/DefaultAPIError'
77
76
  import { workspaceDictionary } from '../error/dictionary/workspace'
78
77
  import { StackspotAPIError } from '../error/StackspotAPIError'
@@ -80,10 +79,11 @@ import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
80
79
  import { contentClient } from './content'
81
80
  import { FixedFullInputContextResponse, FixedPaginatedActivityResponse, FixedPluginForAppCreationV2Response, FixedWorkflowForCreationResponse, ReplaceResult } from './types'
82
81
  import { workspaceClient } from './workspace'
82
+ import { getApiAddresses } from '../api-addresses'
83
83
 
84
84
  class WorkspaceManagerClient extends ReactQueryNetworkClient {
85
85
  constructor() {
86
- super(apis.workspaceManager.url, defaults)
86
+ super(getApiAddresses().workspaceManager.url, defaults)
87
87
  }
88
88
 
89
89
  protected buildStackSpotError(error: HttpError): StackspotAPIError {
@@ -1,14 +1,14 @@
1
1
  import { HttpError } from '@oazapfts/runtime'
2
2
  import { clearUserHistory, defaults, deleteUserHistoryItem, getUserHistory, search } from '../api/workspaceSearchEngine'
3
- import apis from '../apis.json'
4
3
  import { DefaultAPIError } from '../error/DefaultAPIError'
5
4
  import { baseDictionary } from '../error/dictionary/base'
6
5
  import { StackspotAPIError } from '../error/StackspotAPIError'
7
6
  import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
7
+ import { getApiAddresses } from '../api-addresses'
8
8
 
9
9
  class WorkspaceSearchClient extends ReactQueryNetworkClient {
10
10
  constructor() {
11
- super(apis.workspaceSearchEngine.url, defaults)
11
+ super(getApiAddresses().workspaceSearchEngine.url, defaults)
12
12
  }
13
13
 
14
14
  protected buildStackSpotError(error: HttpError): StackspotAPIError {
@@ -82,16 +82,16 @@ import {
82
82
  workspaceVariableV2Controllerupsert,
83
83
  } from '../api/workspace'
84
84
 
85
- import apis from '../apis.json'
86
85
  import { DefaultAPIError } from '../error/DefaultAPIError'
87
86
  import { workspaceDictionary } from '../error/dictionary/workspace'
88
87
  import { StackspotAPIError } from '../error/StackspotAPIError'
89
88
  import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
90
89
  import { OperationObject } from '../network/types'
90
+ import { getApiAddresses } from '../api-addresses'
91
91
 
92
92
  class WorkspaceClient extends ReactQueryNetworkClient {
93
93
  constructor() {
94
- super(apis.workspace.url, defaults)
94
+ super(getApiAddresses().workspace.url, defaults)
95
95
  }
96
96
 
97
97
  protected buildStackSpotError(error: HttpError): StackspotAPIError {
@@ -1,6 +1,5 @@
1
1
  import { Dictionary, Language } from '@stack-spot/portal-translate'
2
2
  import { every, isString } from 'lodash'
3
- import { ErrorResponse, ValidationDetails } from '../api/account'
4
3
  import { actionDetails } from './dictionary/action-details'
5
4
  import { baseDictionary } from './dictionary/base'
6
5
  import { cntFields } from './dictionary/cnt-fields'
@@ -8,6 +7,7 @@ import { workspaceDetails } from './dictionary/workspace-details'
8
7
  import { workspaceFields } from './dictionary/workspace-fields'
9
8
  import { ignoredTitleErrorCodes } from './IgnoredErrorCodes'
10
9
  import { ErrorDetailsProperties, StackspotAPIError } from './StackspotAPIError'
10
+ import { ErrorResponse, LanguageSuggestedMessageKeys, ValidationDetails } from './types'
11
11
 
12
12
  // these details don't say anything the status already doesn't and we'd better use local translations for them.
13
13
  const ignoredDescriptions = [
@@ -35,6 +35,11 @@ function getValues(detail: ValidationDetails) {
35
35
  return detail.values && every(detail.values, isString) ? `\n${detail.values.join('\n')}` : ''
36
36
  }
37
37
 
38
+ function getSuggestedMessages(suggestedMessage: ErrorResponse['suggestedMessages'] | null | undefined, language?: Language) {
39
+ const parseLanguage: Record<Language, LanguageSuggestedMessageKeys> = { pt: 'ptBr', en: 'enUs' }
40
+ return suggestedMessage?.[parseLanguage?.[language || 'en']]
41
+ }
42
+
38
43
  const UNIT_REGEX_TEMPLATE = /{\d}/g
39
44
  const RANGE_REGEX_TEMPLATE = /{1-n}/g
40
45
 
@@ -61,21 +66,39 @@ function createMessage(status: number, raw: ErrorResponse, dictionary: Dictionar
61
66
  const dictDetails = (detailsDictionary[api?.toLowerCase() as keyof typeof detailsDictionary] ?? {})[language || 'en']
62
67
  const dictionaryDetails = raw.code && dictDetails ? dictDetails[raw.code] : {}
63
68
 
64
- if (!raw.validationDetails?.length) return { description: title, ...dictionaryDetails }
69
+ if (raw?.validationDetails?.length) {
65
70
 
66
- const details = raw.validationDetails?.map((detail) => {
67
- const dict: Record<string, string> = (fieldDictionary[api?.toLowerCase() as keyof typeof fieldDictionary] ?? {})[language || 'en'] ?? {}
68
- const codeTranslatedMessage = raw.code !== detail.code && dictionary[language || 'en'][detail.code]
71
+ const suggestedMessages = raw.validationDetails.map((detail) =>
72
+ getSuggestedMessages(detail?.suggestedMessages, language)).filter((msg) => !!msg)
69
73
 
70
- if (codeTranslatedMessage && containsNumberInBraces(codeTranslatedMessage) && (detail.values?.length || detail.field?.length)) {
71
- const value = detail.values?.length ? detail.values : (detail.field ? [detail.field] : [])
72
- return interpolateErrors(codeTranslatedMessage, value, dict)
74
+ if (suggestedMessages.length) {
75
+ return { description: suggestedMessages.join('\n'), ...dictionaryDetails }
73
76
  }
74
77
 
75
- const name = dict[detail.code] || detail.field || codeTranslatedMessage || detail.details || ''
76
- return `${name}${getValues(detail)}`
77
- })?.filter(d => !!d)
78
- return { description: details ? `${title}\n${details?.join('\n')}` : title, ...dictionaryDetails }
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 }
79
102
  }
80
103
 
81
104
  /**
@@ -0,0 +1,21 @@
1
+ export type LanguageSuggestedMessageKeys = 'ptBr' | 'enUs';
2
+
3
+ export type SuggestedMessage = {
4
+ [key in LanguageSuggestedMessageKeys]: string | null
5
+ };
6
+
7
+ export type ValidationDetails = {
8
+ code: string,
9
+ field?: string,
10
+ details?: string,
11
+ values?: string[],
12
+ suggestedMessages?: SuggestedMessage | null,
13
+ };
14
+
15
+ export type ErrorResponse = {
16
+ code: string,
17
+ status: number,
18
+ details: string,
19
+ validationDetails?: ValidationDetails[],
20
+ suggestedMessages?: SuggestedMessage | null,
21
+ };
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { CancelledError } from '@tanstack/react-query'
2
- export { apiAddresses } from './api-addresses'
2
+ export { apiAddresses, getApiAddresses, getBaseUrlWithOverride, setApisOverride } from './api-addresses'
3
3
  export { accountClient } from './client/account'
4
4
  export { agentClient } from './client/agent'
5
5
  export { agentToolsClient } from './client/agent-tools'
@@ -3,6 +3,7 @@ import { requestPermission } from '@stack-spot/opa'
3
3
  import { events } from 'fetch-event-stream'
4
4
  import { StackspotAPIError } from '../error/StackspotAPIError'
5
5
  import { Env, FetchEventStream, HTTPMethod, SessionManager } from './types'
6
+ import { getBaseUrlWithOverride } from '../api-addresses'
6
7
 
7
8
  /**
8
9
  * A set of methods for performing network requests to an API.
@@ -54,6 +55,15 @@ export abstract class NetworkClient {
54
55
  private uninitializedError() {
55
56
  return new Error('Please, call "NetworkClient.setup(sessionManager, env)" before attempting to make a request.')
56
57
  }
58
+
59
+ /**
60
+ * Resolves the final base URL for the current environment.
61
+ * If a local API override exists for the current environment and current resource (api name), it will be use instead.
62
+ * @returns the final baseURL for the current environment, considering overrides if available.
63
+ */
64
+ protected getBaseURL(): string {
65
+ return getBaseUrlWithOverride(this.baseURL, NetworkClient.env);
66
+ }
57
67
 
58
68
  /**
59
69
  * Builds a URL with the `baseUrl` of this network client and the `path` passed as parameter.
@@ -65,7 +75,7 @@ export abstract class NetworkClient {
65
75
  // paths must not start with "/", otherwise, the base url will not be fully appended to it.
66
76
  const fixedPath = path.replace(/^\//, '')
67
77
  // the baseUrl must end with "/", otherwise, the last of its part will get replaced by the path, instead of concatenated with.
68
- const fixedBaseUrl = this.baseURL[NetworkClient.env].replace(/([^/])$/, '$1/')
78
+ const fixedBaseUrl = this.getBaseURL().replace(/([^/])$/, '$1/')
69
79
  return new URL(fixedPath, fixedBaseUrl)
70
80
  }
71
81