@stack-spot/portal-network 0.1.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 (186) hide show
  1. package/.generate-api.failed.json +1 -0
  2. package/dist/api/account.d.ts +2368 -0
  3. package/dist/api/account.d.ts.map +1 -0
  4. package/dist/api/account.js +1521 -0
  5. package/dist/api/account.js.map +1 -0
  6. package/dist/api/ai.d.ts +1432 -0
  7. package/dist/api/ai.d.ts.map +1 -0
  8. package/dist/api/ai.js +1342 -0
  9. package/dist/api/ai.js.map +1 -0
  10. package/dist/api/apiRuntime.d.ts +922 -0
  11. package/dist/api/apiRuntime.d.ts.map +1 -0
  12. package/dist/api/apiRuntime.js +599 -0
  13. package/dist/api/apiRuntime.js.map +1 -0
  14. package/dist/api/cloudAccount.d.ts +473 -0
  15. package/dist/api/cloudAccount.d.ts.map +1 -0
  16. package/dist/api/cloudAccount.js +300 -0
  17. package/dist/api/cloudAccount.js.map +1 -0
  18. package/dist/api/cloudServices.d.ts +1233 -0
  19. package/dist/api/cloudServices.d.ts.map +1 -0
  20. package/dist/api/cloudServices.js +715 -0
  21. package/dist/api/cloudServices.js.map +1 -0
  22. package/dist/api/insights.d.ts +123 -0
  23. package/dist/api/insights.d.ts.map +1 -0
  24. package/dist/api/insights.js +112 -0
  25. package/dist/api/insights.js.map +1 -0
  26. package/dist/api/plugin.d.ts +368 -0
  27. package/dist/api/plugin.d.ts.map +1 -0
  28. package/dist/api/plugin.js +218 -0
  29. package/dist/api/plugin.js.map +1 -0
  30. package/dist/api/serviceCatalog.d.ts +737 -0
  31. package/dist/api/serviceCatalog.d.ts.map +1 -0
  32. package/dist/api/serviceCatalog.js +611 -0
  33. package/dist/api/serviceCatalog.js.map +1 -0
  34. package/dist/api/workflows.d.ts +366 -0
  35. package/dist/api/workflows.d.ts.map +1 -0
  36. package/dist/api/workflows.js +175 -0
  37. package/dist/api/workflows.js.map +1 -0
  38. package/dist/api/workspace.js +1476 -0
  39. package/dist/api/workspace.js.map +1 -0
  40. package/dist/api/workspaceManager.d.ts +1121 -0
  41. package/dist/api/workspaceManager.d.ts.map +1 -0
  42. package/dist/api/workspaceManager.js +357 -0
  43. package/dist/api/workspaceManager.js.map +1 -0
  44. package/dist/api/workspaceSearchEngine.d.ts +93 -0
  45. package/dist/api/workspaceSearchEngine.d.ts.map +1 -0
  46. package/dist/api/workspaceSearchEngine.js +55 -0
  47. package/dist/api/workspaceSearchEngine.js.map +1 -0
  48. package/dist/apis.json +129 -0
  49. package/dist/client/account.d.ts +46 -0
  50. package/dist/client/account.d.ts.map +1 -0
  51. package/dist/client/account.js +104 -0
  52. package/dist/client/account.js.map +1 -0
  53. package/dist/error/CanceledError.d.ts +5 -0
  54. package/dist/error/CanceledError.d.ts.map +1 -0
  55. package/dist/error/CanceledError.js +7 -0
  56. package/dist/error/CanceledError.js.map +1 -0
  57. package/dist/error/DefaultAPIError.d.ts +9 -0
  58. package/dist/error/DefaultAPIError.d.ts.map +1 -0
  59. package/dist/error/DefaultAPIError.js +58 -0
  60. package/dist/error/DefaultAPIError.js.map +1 -0
  61. package/dist/error/StackspotAPIError.d.ts +19 -0
  62. package/dist/error/StackspotAPIError.d.ts.map +1 -0
  63. package/dist/error/StackspotAPIError.js +39 -0
  64. package/dist/error/StackspotAPIError.js.map +1 -0
  65. package/dist/error/dictionary/account.d.ts +55 -0
  66. package/dist/error/dictionary/account.d.ts.map +1 -0
  67. package/dist/error/dictionary/account.js +55 -0
  68. package/dist/error/dictionary/account.js.map +1 -0
  69. package/dist/error/dictionary/action.d.ts +163 -0
  70. package/dist/error/dictionary/action.d.ts.map +1 -0
  71. package/dist/error/dictionary/action.js +163 -0
  72. package/dist/error/dictionary/action.js.map +1 -0
  73. package/dist/error/dictionary/base.d.ts +21 -0
  74. package/dist/error/dictionary/base.d.ts.map +1 -0
  75. package/dist/error/dictionary/base.js +21 -0
  76. package/dist/error/dictionary/base.js.map +1 -0
  77. package/dist/error/dictionary/cnt-fields.d.ts +13 -0
  78. package/dist/error/dictionary/cnt-fields.d.ts.map +1 -0
  79. package/dist/error/dictionary/cnt-fields.js +13 -0
  80. package/dist/error/dictionary/cnt-fields.js.map +1 -0
  81. package/dist/error/dictionary/cnt.d.ts +79 -0
  82. package/dist/error/dictionary/cnt.d.ts.map +1 -0
  83. package/dist/error/dictionary/cnt.js +79 -0
  84. package/dist/error/dictionary/cnt.js.map +1 -0
  85. package/dist/error/dictionary/rte.d.ts +23 -0
  86. package/dist/error/dictionary/rte.d.ts.map +1 -0
  87. package/dist/error/dictionary/rte.js +23 -0
  88. package/dist/error/dictionary/rte.js.map +1 -0
  89. package/dist/error/dictionary/rtm.d.ts +9 -0
  90. package/dist/error/dictionary/rtm.d.ts.map +1 -0
  91. package/dist/error/dictionary/rtm.js +9 -0
  92. package/dist/error/dictionary/rtm.js.map +1 -0
  93. package/dist/error/dictionary/workspace-fields.d.ts +9 -0
  94. package/dist/error/dictionary/workspace-fields.d.ts.map +1 -0
  95. package/dist/error/dictionary/workspace-fields.js +9 -0
  96. package/dist/error/dictionary/workspace-fields.js.map +1 -0
  97. package/dist/error/dictionary/workspace.d.ts +99 -0
  98. package/dist/error/dictionary/workspace.d.ts.map +1 -0
  99. package/dist/error/dictionary/workspace.js +99 -0
  100. package/dist/error/dictionary/workspace.js.map +1 -0
  101. package/dist/index.d.ts +6 -0
  102. package/dist/index.d.ts.map +1 -0
  103. package/dist/index.js +6 -0
  104. package/dist/index.js.map +1 -0
  105. package/dist/network/AutoMutation.d.ts +10 -0
  106. package/dist/network/AutoMutation.d.ts.map +1 -0
  107. package/dist/network/AutoMutation.js +20 -0
  108. package/dist/network/AutoMutation.js.map +1 -0
  109. package/dist/network/AutoOperation.d.ts +19 -0
  110. package/dist/network/AutoOperation.d.ts.map +1 -0
  111. package/dist/network/AutoOperation.js +99 -0
  112. package/dist/network/AutoOperation.js.map +1 -0
  113. package/dist/network/AutoQuery.d.ts +19 -0
  114. package/dist/network/AutoQuery.d.ts.map +1 -0
  115. package/dist/network/AutoQuery.js +70 -0
  116. package/dist/network/AutoQuery.js.map +1 -0
  117. package/dist/network/ManualMutation.d.ts +11 -0
  118. package/dist/network/ManualMutation.d.ts.map +1 -0
  119. package/dist/network/ManualMutation.js +32 -0
  120. package/dist/network/ManualMutation.js.map +1 -0
  121. package/dist/network/ManualOperation.d.ts +13 -0
  122. package/dist/network/ManualOperation.d.ts.map +1 -0
  123. package/dist/network/ManualOperation.js +53 -0
  124. package/dist/network/ManualOperation.js.map +1 -0
  125. package/dist/network/ManualQuery.d.ts +20 -0
  126. package/dist/network/ManualQuery.d.ts.map +1 -0
  127. package/dist/network/ManualQuery.js +77 -0
  128. package/dist/network/ManualQuery.js.map +1 -0
  129. package/dist/network/NetworkClient.d.ts +20 -0
  130. package/dist/network/NetworkClient.d.ts.map +1 -0
  131. package/dist/network/NetworkClient.js +85 -0
  132. package/dist/network/NetworkClient.js.map +1 -0
  133. package/dist/network/ReactQueryNetworkClient.d.ts +16 -0
  134. package/dist/network/ReactQueryNetworkClient.d.ts.map +1 -0
  135. package/dist/network/ReactQueryNetworkClient.js +125 -0
  136. package/dist/network/ReactQueryNetworkClient.js.map +1 -0
  137. package/dist/network/react-query-client.d.ts +3 -0
  138. package/dist/network/react-query-client.d.ts.map +1 -0
  139. package/dist/network/react-query-client.js +3 -0
  140. package/dist/network/react-query-client.js.map +1 -0
  141. package/dist/network/types.d.ts +55 -0
  142. package/dist/network/types.d.ts.map +1 -0
  143. package/dist/network/types.js +2 -0
  144. package/dist/network/types.js.map +1 -0
  145. package/package.json +56 -0
  146. package/readme.md +1 -0
  147. package/scripts/generate-apis.ts +134 -0
  148. package/src/api/account.ts +4793 -0
  149. package/src/api/ai.ts +3121 -0
  150. package/src/api/apiRuntime.ts +2029 -0
  151. package/src/api/cloudAccount.ts +1133 -0
  152. package/src/api/cloudServices.ts +2872 -0
  153. package/src/api/insights.ts +264 -0
  154. package/src/api/plugin.ts +685 -0
  155. package/src/api/serviceCatalog.ts +2908 -0
  156. package/src/api/workflows.ts +709 -0
  157. package/src/api/workspace.ts +5178 -0
  158. package/src/api/workspaceManager.ts +1516 -0
  159. package/src/api/workspaceSearchEngine.ts +153 -0
  160. package/src/apis.json +129 -0
  161. package/src/client/account.ts +52 -0
  162. package/src/error/CanceledError.ts +7 -0
  163. package/src/error/DefaultAPIError.ts +51 -0
  164. package/src/error/StackspotAPIError.ts +31 -0
  165. package/src/error/dictionary/account.ts +56 -0
  166. package/src/error/dictionary/action.ts +206 -0
  167. package/src/error/dictionary/base.ts +22 -0
  168. package/src/error/dictionary/cnt-fields.ts +14 -0
  169. package/src/error/dictionary/cnt.ts +80 -0
  170. package/src/error/dictionary/rte.ts +24 -0
  171. package/src/error/dictionary/rtm.ts +10 -0
  172. package/src/error/dictionary/workspace-fields.ts +10 -0
  173. package/src/error/dictionary/workspace.ts +100 -0
  174. package/src/index.ts +5 -0
  175. package/src/network/AutoMutation.ts +25 -0
  176. package/src/network/AutoOperation.ts +88 -0
  177. package/src/network/AutoQuery.ts +80 -0
  178. package/src/network/ManualMutation.ts +41 -0
  179. package/src/network/ManualOperation.ts +55 -0
  180. package/src/network/ManualQuery.ts +93 -0
  181. package/src/network/NetworkClient.ts +93 -0
  182. package/src/network/ReactQueryNetworkClient.ts +154 -0
  183. package/src/network/react-query-client.ts +3 -0
  184. package/src/network/types.ts +82 -0
  185. package/tsconfig.build.json +4 -0
  186. package/tsconfig.json +10 -0
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Search Engine API
3
+ * v1.0.0
4
+ * DO NOT MODIFY - This file has been generated using oazapfts.
5
+ * See https://www.npmjs.com/package/oazapfts
6
+ */
7
+ import * as Oazapfts from "@oazapfts/runtime";
8
+ import * as QS from "@oazapfts/runtime/query";
9
+ export const defaults: Oazapfts.Defaults<Oazapfts.CustomHeaders> = {
10
+ headers: {},
11
+ baseUrl: "https://workspace-search-engine-api.dev.stackspot.com",
12
+ };
13
+ const oazapfts = Oazapfts.runtime(defaults);
14
+ export const servers = {
15
+ generatedServerUrl: "https://workspace-search-engine-api.dev.stackspot.com"
16
+ };
17
+ export type ExtraDataResponse = {
18
+ key: string;
19
+ value: string;
20
+ };
21
+ export type SearchDataItemResponse = {
22
+ /** The resource identifier. */
23
+ identifier?: string;
24
+ /** The resource slug. */
25
+ identifierSlug?: string;
26
+ /** The resource description. */
27
+ description?: string;
28
+ /** The resource display name. */
29
+ name?: string;
30
+ /** The resource extra data correlated to itself (ie: the workspace ID of an application) */
31
+ extraData?: ExtraDataResponse[];
32
+ };
33
+ export type SearchDataResponse = {
34
+ /** The resource type category of the items */
35
+ category?: string;
36
+ /** The total result count for the searched text */
37
+ totalCount?: number;
38
+ /** List of the resources found */
39
+ items?: SearchDataItemResponse[];
40
+ };
41
+ export type Pagination = {
42
+ /** Total pages */
43
+ totalPages?: number;
44
+ /** Total pageable elements */
45
+ totalElements?: number;
46
+ /** Current page number starting from 0 */
47
+ pageNumber?: number;
48
+ /** Current page size. Fixed 50 items. */
49
+ pageSize?: number;
50
+ /** Has more results to return. */
51
+ hasNext?: boolean;
52
+ };
53
+ export type SearchResponse = {
54
+ content: SearchDataResponse[];
55
+ pagination?: Pagination;
56
+ };
57
+ export type ValidationDetails = {
58
+ code: string;
59
+ field?: string;
60
+ details?: string;
61
+ values?: string[];
62
+ };
63
+ export type ErrorResponse = {
64
+ code: string;
65
+ status: number;
66
+ details: string;
67
+ validationDetails?: ValidationDetails[];
68
+ };
69
+ export type HistoryItemResponse = {
70
+ id: string;
71
+ searchText: string;
72
+ };
73
+ export type SearchHistoryResponse = {
74
+ items: HistoryItemResponse[];
75
+ };
76
+ /**
77
+ * Search all Stackspot resources using semantic search.
78
+ */
79
+ export function search({ q, category, page }: {
80
+ q: string;
81
+ category?: string;
82
+ page?: number;
83
+ }, opts?: Oazapfts.RequestOpts) {
84
+ return oazapfts.ok(oazapfts.fetchJson<{
85
+ status: 200;
86
+ data: SearchResponse;
87
+ } | {
88
+ status: 400;
89
+ data: ErrorResponse;
90
+ } | {
91
+ status: 500;
92
+ data: ErrorResponse;
93
+ }>(`/v1/search${QS.query(QS.explode({
94
+ q,
95
+ category,
96
+ page
97
+ }))}`, {
98
+ ...opts
99
+ }));
100
+ }
101
+ /**
102
+ * Get the logged-in user search history list.
103
+ */
104
+ export function getUserHistory(opts?: Oazapfts.RequestOpts) {
105
+ return oazapfts.ok(oazapfts.fetchJson<{
106
+ status: 200;
107
+ data: SearchHistoryResponse;
108
+ } | {
109
+ status: 403;
110
+ data: ErrorResponse;
111
+ } | {
112
+ status: 500;
113
+ data: ErrorResponse;
114
+ }>("/v1/search/history", {
115
+ ...opts
116
+ }));
117
+ }
118
+ /**
119
+ * Clear the logged-in user search history.
120
+ */
121
+ export function clearUserHistory(opts?: Oazapfts.RequestOpts) {
122
+ return oazapfts.ok(oazapfts.fetchJson<{
123
+ status: 204;
124
+ } | {
125
+ status: 403;
126
+ data: ErrorResponse;
127
+ } | {
128
+ status: 500;
129
+ data: ErrorResponse;
130
+ }>("/v1/search/history", {
131
+ ...opts,
132
+ method: "DELETE"
133
+ }));
134
+ }
135
+ /**
136
+ * Delete the logged-in user specific search history item.
137
+ */
138
+ export function deleteUserHistoryItem({ itemId }: {
139
+ itemId: string;
140
+ }, opts?: Oazapfts.RequestOpts) {
141
+ return oazapfts.ok(oazapfts.fetchJson<{
142
+ status: 204;
143
+ } | {
144
+ status: 403;
145
+ data: ErrorResponse;
146
+ } | {
147
+ status: 500;
148
+ data: ErrorResponse;
149
+ }>(`/v1/search/history/${encodeURIComponent(itemId)}`, {
150
+ ...opts,
151
+ method: "DELETE"
152
+ }));
153
+ }
package/src/apis.json ADDED
@@ -0,0 +1,129 @@
1
+ {
2
+ "ai": {
3
+ "url": {
4
+ "dev": "https://code-buddy-api.dev.stackspot.com",
5
+ "stg": "https://code-buddy-api.stg.stackspot.com",
6
+ "prd": "https://genai-code-buddy-api.stackspot.com"
7
+ },
8
+ "docs": "/openapi.json"
9
+ },
10
+ "workspace": {
11
+ "url": {
12
+ "dev": "https://workspace-workspace-api.dev.stackspot.com",
13
+ "stg": "https://workspace-workspace-api.stg.stackspot.com",
14
+ "prd": "https://workspace.v1.stackspot.com"
15
+ },
16
+ "docs": "/v3/api-docs"
17
+ },
18
+ "account": {
19
+ "url": {
20
+ "dev": "https://account-account-api.dev.stackspot.com",
21
+ "stg": "https://account-account-api.stg.stackspot.com",
22
+ "prd": "https://account.v1.stackspot.com"
23
+ },
24
+ "docs": "/v3/api-docs"
25
+ },
26
+ "content": {
27
+ "url": {
28
+ "dev": "https://content-content-api.dev.stackspot.com",
29
+ "stg": "https://content-content-api.stg.stackspot.com",
30
+ "prd": "https://content-api.v1.stackspot.com"
31
+ },
32
+ "docs": "/v3/api-docs"
33
+ },
34
+ "serviceCatalog": {
35
+ "url": {
36
+ "dev": "https://catalog-tech-products-catalog-api.dev.stackspot.com",
37
+ "stg": "https://catalog-tech-products-catalog-api.stg.stackspot.com",
38
+ "prd": "https://catalog-api.v1.stackspot.com"
39
+ },
40
+ "docs": "/v3/api-docs"
41
+ },
42
+ "apiRuntime": {
43
+ "url": {
44
+ "dev": "https://runtime-manager.dev.stackspot.com",
45
+ "stg": "https://runtime-manager.stg.stackspot.com",
46
+ "prd": "https://runtime-engine.v1.stackspot.com"
47
+ },
48
+ "docs": "/v3/api-docs"
49
+ },
50
+ "cloudServices": {
51
+ "url": {
52
+ "dev": "https://cloud-services-cloud-services-api.dev.stackspot.com",
53
+ "stg": "https://cloud-services-cloud-services-api.stg.stackspot.com",
54
+ "prd": "https://cloud-services-api.stackspot.com"
55
+ },
56
+ "docs": "/v3/api-docs"
57
+ },
58
+ "cloudAccount": {
59
+ "url": {
60
+ "dev": "https://account-account-external-connections-api.dev.stackspot.com",
61
+ "stg": "https://account-account-external-connections-api.stg.stackspot.com",
62
+ "prd": "https://account-external-connections-api.stackspot.com"
63
+ },
64
+ "docs": "/v3/api-docs"
65
+ },
66
+ "dataPlatform": {
67
+ "url": {
68
+ "dev": "https://data-platform-metabase.dev.stackspot.com",
69
+ "stg": "https://data-platform-metabase.stg.stackspot.com",
70
+ "prd": "https://data-platform-stackspot-public.stackspot.com"
71
+ },
72
+ "docs": "/v3/api-docs"
73
+ },
74
+ "insights": {
75
+ "url": {
76
+ "dev": "https://insights-insights-api.dev.stackspot.com",
77
+ "stg": "https://insights-insights-api.stg.stackspot.com",
78
+ "prd": "https://insights-api.stackspot.com"
79
+ },
80
+ "docs": "/v3/api-docs"
81
+ },
82
+ "plugin": {
83
+ "url": {
84
+ "dev": "https://content-plugin-api.dev.stackspot.com",
85
+ "stg": "https://content-plugin-api.stg.stackspot.com",
86
+ "prd": "https://plugin-api.v1.stackspot.com"
87
+ },
88
+ "docs": "/openapi.json"
89
+ },
90
+ "workflows": {
91
+ "url": {
92
+ "dev": "https://workflow-workflow-api.dev.stackspot.com",
93
+ "stg": "https://workflow-workflow-api.stg.stackspot.com",
94
+ "prd": "https://workflow-api.v1.stackspot.com"
95
+ },
96
+ "docs": "/openapi.json"
97
+ },
98
+ "workspaceManager": {
99
+ "url": {
100
+ "dev": "https://workspace-workspace-manager.dev.stackspot.com",
101
+ "stg": "https://workspace-workspace-manager.stg.stackspot.com",
102
+ "prd": "https://workspace-manager.v1.stackspot.com"
103
+ },
104
+ "docs": "/v3/api-docs"
105
+ },
106
+ "workspaceSearchEngine": {
107
+ "url": {
108
+ "dev": "https://workspace-search-engine-api.dev.stackspot.com",
109
+ "stg": "https://workspace-search-engine-api.stg.stackspot.com",
110
+ "prd": "https://workspace-search-engine-api.stackspot.com"
111
+ },
112
+ "docs": "/v3/api-docs"
113
+ },
114
+ "permissionValidation": {
115
+ "url": {
116
+ "dev": "https://portal-portal-opa-server.dev.stackspot.com/v1/validate",
117
+ "stg": "https://portal-portal-opa-server.stg.stackspot.com/v1/validate",
118
+ "prd": "https://portal-opa-server.stackspot.com/v1/validate"
119
+ }
120
+ },
121
+ "apiManagement": {
122
+ "url": {
123
+ "dev": "https://api-management-apigw.dev.stackspot.com/api-management",
124
+ "stg": "https://api-management-apigw.stg.stackspot.com/api-management",
125
+ "prd": "https://api-management-apigw.stackspot.com/api-management"
126
+ },
127
+ "docs": "/v3/api-docs"
128
+ }
129
+ }
@@ -0,0 +1,52 @@
1
+ import { HttpError } from '@oazapfts/runtime'
2
+ import {
3
+ accountDataIsAvailable, create, createPartner,
4
+ defaults,
5
+ deletePartner, getFeatures, getPartnerAccount, getPartnersSharingAllowed,
6
+ getPersonalClientCredentials, updatePartnerAccountAdminData, updatePartnerAccountData, validateNewPartnerData,
7
+ validatePartnerAssociationLimit,
8
+ } from '../api/account'
9
+ import apis from '../apis.json'
10
+ import { DefaultAPIError } from '../error/DefaultAPIError'
11
+ import { accountDictionary } from '../error/dictionary/account'
12
+ import { StackspotAPIError } from '../error/StackspotAPIError'
13
+ import { ReactQueryNetworkClient } from '../network/ReactQueryNetworkClient'
14
+
15
+ class AccountClient extends ReactQueryNetworkClient {
16
+ constructor() {
17
+ super(apis.account.url, defaults)
18
+ }
19
+
20
+ protected buildStackSpotError(error: HttpError): StackspotAPIError {
21
+ return new DefaultAPIError(error.data, error.status, accountDictionary, error.headers)
22
+ }
23
+
24
+ generatePersonalClientCredentials = this.mutation(getPersonalClientCredentials)
25
+ create = this.mutation(create)
26
+ isAvailable = this.query(accountDataIsAvailable)
27
+ featureFlags = this.query(getFeatures)
28
+ partners = this.query(getPartnersSharingAllowed)
29
+ partner = this.query(getPartnerAccount)
30
+ createPartner = this.mutation(createPartner)
31
+ updatePartner = this.mutation(updatePartnerAccountData)
32
+ updatePartnerAdmin = this.mutation(updatePartnerAccountAdminData)
33
+ deactivatePartner = this.mutation(deletePartner)
34
+ validateNewPartnerData = this.mutation(validateNewPartnerData)
35
+ validatePartnerAssociationLimit = this.query({
36
+ name: 'validatePartnerAssociationLimit',
37
+ request: async (signal) => {
38
+ try {
39
+ await validatePartnerAssociationLimit({ signal })
40
+ return { isValid: true, message: '' }
41
+ } catch (error) {
42
+ if (error instanceof HttpError) {
43
+ const stkError = this.buildStackSpotError(error)
44
+ if (stkError.status === 422 || stkError.code === 'BAD_USER_INPUT') return { isValid: false, message: stkError.translate() }
45
+ }
46
+ throw error
47
+ }
48
+ },
49
+ })
50
+ }
51
+
52
+ export const accountClient = new AccountClient()
@@ -0,0 +1,7 @@
1
+ import { StackspotAPIError } from './StackspotAPIError'
2
+
3
+ export class CanceledError extends StackspotAPIError {
4
+ constructor() {
5
+ super({ status: 0, message: lang => lang === 'en' ? 'Canceled by the user' : 'Cancelado pelo usuário' })
6
+ }
7
+ }
@@ -0,0 +1,51 @@
1
+ import { Dictionary, Language } from '@stack-spot/portal-translate'
2
+ import { every, isEmpty, isString } from 'lodash'
3
+ import { ErrorResponse } from '../api/account'
4
+ import { StackspotAPIError } from './StackspotAPIError'
5
+ import { baseDictionary } from './dictionary/base'
6
+ import { cntFields } from './dictionary/cnt-fields'
7
+ import { workspaceFields } from './dictionary/workspace-fields'
8
+
9
+ // these details don't say anything the status already doesn't and we'd better use local translations for them.
10
+ const ignoredDescriptions = [
11
+ 'internal server error', 'not found', 'gateway timeout', 'temporally unavailable', 'forbidden', 'unauthorized', 'bad request',
12
+ ]
13
+
14
+ const fieldDictionary = {
15
+ cnt: cntFields,
16
+ wks: workspaceFields,
17
+ }
18
+
19
+ function getTitle(raw: ErrorResponse, dictionary: Dictionary, language: Language) {
20
+ if (dictionary[language][raw.code]) return dictionary[language][raw.code]
21
+ if (!ignoredDescriptions.includes(raw.details)) return raw.details
22
+ return (baseDictionary as Dictionary)[language][raw.status] || baseDictionary[language].defaultTitle
23
+ }
24
+
25
+ function createMessage(raw: ErrorResponse, dictionary: Dictionary, language: Language) {
26
+ const title = getTitle(raw, dictionary, language)
27
+ if (isEmpty(raw.validationDetails)) return title
28
+ const api = raw.code?.split(/[-_]/)[0]
29
+ const details = raw.validationDetails?.map((detail) => {
30
+ const dict: Record<string, string> = (fieldDictionary[api?.toLowerCase() as keyof typeof fieldDictionary] ?? {})[language] ?? {}
31
+ const name = dict[detail.code] || detail.field || (raw.code !== detail.code && dictionary[language][detail.code]) || ''
32
+ return name ? `${name}${detail.values && every(detail.values, isString) ? `\n${detail.values.join('\n')}` : ''}` : undefined
33
+ })?.filter(d => !!d)
34
+ return `${title}\n${details?.join('\n')}`
35
+ }
36
+
37
+ export class DefaultAPIError extends StackspotAPIError {
38
+ data?: ErrorResponse
39
+ raw?: any
40
+
41
+ constructor(rawResponse: any, status: number, dictionary: Dictionary, headers?: Headers) {
42
+ super({
43
+ status: status,
44
+ code: rawResponse.code,
45
+ message: language => createMessage(rawResponse, dictionary, language),
46
+ headers,
47
+ })
48
+ this.raw = rawResponse
49
+ if (this.raw?.code !== undefined && this.raw?.status !== undefined && this.raw?.details !== undefined) this.data = rawResponse
50
+ }
51
+ }
@@ -0,0 +1,31 @@
1
+ import { Language, getLanguage } from '@stack-spot/portal-translate'
2
+
3
+ type InternationalizedMessage = (language: Language) => string
4
+
5
+ interface ErrorProperties {
6
+ status: number,
7
+ headers?: Headers,
8
+ code?: string,
9
+ message?: InternationalizedMessage | string,
10
+ stack?: string,
11
+ }
12
+
13
+ export class StackspotAPIError extends Error {
14
+ status: number
15
+ headers: Headers | undefined
16
+ code: string | undefined
17
+ private intl?: InternationalizedMessage
18
+
19
+ constructor({ status, code, headers, message, stack }: ErrorProperties) {
20
+ super(`Stackspot API error (network ${status}): ${typeof message === 'string' ? message : message?.('en') || message?.('pt') || code || 'unknown'}`)
21
+ this.status = status
22
+ this.code = code
23
+ this.headers = headers
24
+ this.stack = stack
25
+ this.intl = typeof message === 'string' ? () => message : message
26
+ }
27
+
28
+ translate(language: Language = getLanguage()) {
29
+ return this.intl?.(language) ?? this.message
30
+ }
31
+ }
@@ -0,0 +1,56 @@
1
+ import { Dictionary } from '@stack-spot/portal-translate'
2
+
3
+ export const accountDictionary = {
4
+ en: {
5
+ ACC_BAD_REQUEST_ERROR: 'The provided data is invalid or inconsistent.',
6
+ ACC_ATTR_INVALID_EVALUATED_FROM_VALIDATIONS_LENGTH: 'The field {1} must have between {2} and {3} characters long.',
7
+ ACC_STUDIO_ALREADY_EXISTS_FOR_ACCOUNT: 'A Studio with this name already exists. Please choose a new name.',
8
+ ACC_UNABLE_DELETE_TEAM_CONSTRAINT_VIOLATION_ERROR: 'The Team cannot be deleted because it is linked to other resources in the account.',
9
+ ACC_CREDENTIAL_ALREADY_EXISTS_FOR_USER: 'Please configure the SCM to continue.',
10
+ ACC_CREDENTIAL_NOT_FOUND_ERROR: 'SCM Credentials not found.',
11
+ ACC_FIELDS_EXTERNALNAME_IS_INVALID: 'The internal identifier contains characters or words that are not allowed.',
12
+ ACC_MALFORMED_FIELDS_IN_PAYLOAD: 'Check the fields, some entries are invalid.',
13
+ ACC_TEAM_ALREADY_EXISTS_FOR_ACCOUNT_AND_EXTERNAL_NAME: 'This information has already been used to register a Team. Please use a different one.',
14
+ ACC_ACCOUNT_DATA_UNAVAILABLE_TO_REGISTER_ACCOUNT_FREEMIUM: 'This name is already in use. Please choose a new one.',
15
+ ACC_USER_NOT_FOUND_TO_REGISTER_ACCOUNT_FREEMIUM: 'User not found. Please log in with GitHub to register for a Personal acccount.',
16
+ ACC_ALREADY_EXISTS_ACCOUNT_FREEMIUM_TO_USER: 'You already have a Personal account. Please log in to use your StackSpot Account.',
17
+ ACC_USER_NOT_ALLOWED_TO_REGISTER_ACCOUNT_FREEMIUM: "Your current domain doesn't allow Personal account registration. Please try registering with a different domain.",
18
+ ACC_IMPORT_ACCOUNT_MEMBERS_ALREADY_EXISTS_FOR_ACCOUNT: 'An import is currently in progress. Please wait for it to complete or contact StackSpot support for more information.',
19
+ ACC_SERVICE_CREDENTIAL_PERMISSIONS_INCONSISTENT_TO_ASSOCIATION: 'The permissions provided are inconsistent with this Service Credential.',
20
+ ACC_SERVICE_CREDENTIAL_TEAMS_INCONSISTENT_TO_ASSOCIATION: 'Some teams are not authorized to use this Service Credential.',
21
+ ACC_SERVICE_CREDENTIAL_TEAMS_INCONSISTENT_TO_DISASSOCIATION: 'There is an inconsistency in disassociating the Team with this Service Credential.',
22
+ ACC_SERVICE_CREDENTIAL_ALREADY_EXISTS_FOR_ACCOUNT: 'A Service Credential with this name already exists.',
23
+ ACC_SERVICE_CREDENTIAL_NOT_FOUND: 'Credencial de Serviço não encontrada.',
24
+ ACC_ACCOUNT_CREATION_DATA_ERROR: 'This partner is already registered.',
25
+ ACC_PARTNER_ACCOUNT_ADMIN_UPDATE_NAME_ERROR: 'It is impossible to change only the name or surname of the partner Account Administrator.',
26
+ ACC_ACCOUNT_PARTNER_CANT_BE_INACTIVATED: 'This partner cannot be deactivated due to associated APIs or products.',
27
+ ACC_ACCOUNT_CREATION_PARTNER_ASSOCIATION_LIMIT: 'Your account has reached the limit of associations with partner accounts.',
28
+ ACC_INVALID_PASSWORD: "Invalid password. Please make sure it meets the requirements and hasn't been used before.",
29
+ },
30
+ pt: {
31
+ ACC_BAD_REQUEST_ERROR: 'Os dados informados estão inválidos ou inconsistentes.',
32
+ ACC_ATTR_INVALID_EVALUATED_FROM_VALIDATIONS_LENGTH: 'O campo {1} deve ter um tamanho entre {2} e {3}.',
33
+ ACC_STUDIO_ALREADY_EXISTS_FOR_ACCOUNT: 'Já existe um Estúdio com esse nome. Por favor, escolha outro.',
34
+ ACC_UNABLE_DELETE_TEAM_CONSTRAINT_VIOLATION_ERROR: 'Não é possível excluir a Equipe porque ela está vinculada a outros recursos da conta.',
35
+ ACC_CREDENTIAL_ALREADY_EXISTS_FOR_USER: 'Para continuar, configure o SCM.',
36
+ ACC_CREDENTIAL_NOT_FOUND_ERROR: 'Credenciais de SCM não encontradas.',
37
+ ACC_FIELDS_EXTERNALNAME_IS_INVALID: 'O identificador interno contém caracteres ou palavras não permitidos.',
38
+ ACC_MALFORMED_FIELDS_IN_PAYLOAD: 'Verifique os campos, alguns estão inválidos.',
39
+ ACC_TEAM_ALREADY_EXISTS_FOR_ACCOUNT_AND_EXTERNAL_NAME: 'Essas informações já foram usadas para registrar uma Equipe. Por favor, utilize outras informações.',
40
+ ACC_ACCOUNT_DATA_UNAVAILABLE_TO_REGISTER_ACCOUNT_FREEMIUM: 'Este nome já está em uso. Por favor, escolha um novo.',
41
+ ACC_USER_NOT_FOUND_TO_REGISTER_ACCOUNT_FREEMIUM: 'User não encontrado. Faça login com Github para registrar uma conta Personal.',
42
+ ACC_ALREADY_EXISTS_ACCOUNT_FREEMIUM_TO_USER: 'Você já tem uma Conta Personal. Faça login para usar a sua conta StackSpot.',
43
+ ACC_USER_NOT_ALLOWED_TO_REGISTER_ACCOUNT_FREEMIUM: 'Seu domínio atual não permite o registro de uma Conta Personal. Por favor, use um domínio diferente.',
44
+ ACC_IMPORT_ACCOUNT_MEMBERS_ALREADY_EXISTS_FOR_ACCOUNT: 'Existe uma importação em andamento. Aguarde a conclusão ou contate o suporte da StackSpot para mais informações.',
45
+ ACC_SERVICE_CREDENTIAL_PERMISSIONS_INCONSISTENT_TO_ASSOCIATION: 'As permissões fornecidas são inconsistentes para essa Credencial de Serviço.',
46
+ ACC_SERVICE_CREDENTIAL_TEAMS_INCONSISTENT_TO_ASSOCIATION: 'Algumas Equipes não estão alinhadas para associar a essa Credencial de Serviço.',
47
+ ACC_SERVICE_CREDENTIAL_TEAMS_INCONSISTENT_TO_DISASSOCIATION: 'Há uma inconsistência na desassociação da Equipe com essa Credencial de Serviço.',
48
+ ACC_SERVICE_CREDENTIAL_ALREADY_EXISTS_FOR_ACCOUNT: 'Já existe uma Credencial de Serviço com esse nome.',
49
+ ACC_SERVICE_CREDENTIAL_NOT_FOUND: 'Service Credential not found.',
50
+ ACC_ACCOUNT_CREATION_DATA_ERROR: 'Esse Parceiro já está registrado.',
51
+ ACC_PARTNER_ACCOUNT_ADMIN_UPDATE_NAME_ERROR: 'Não é possível alterar apenas o nome ou sobrenome da pessoa que administra a Conta Parceiro.',
52
+ ACC_ACCOUNT_PARTNER_CANT_BE_INACTIVATED: 'Este Parceiro não pode ser inativado devido a APIs ou produtos associados.',
53
+ ACC_ACCOUNT_CREATION_PARTNER_ASSOCIATION_LIMIT: 'Sua conta atingiu o limite de associações com Contas de Parceiros.',
54
+ ACC_INVALID_PASSWORD: 'Senha inválida. Verifique se ela atende aos requisitos e não foi usada anteriormente.',
55
+ },
56
+ } satisfies Dictionary