@stack-spot/portal-network 0.184.0 → 0.185.0-beta.1
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.
- package/CHANGELOG.md +2444 -2412
- package/dist/api/account.js +1 -1
- package/dist/api/agent-tools.js +1 -1
- package/dist/api/agent.js +1 -1
- package/dist/api/ai.js +1 -1
- package/dist/api/apiManagement.js +1 -1
- package/dist/api/apiRuntime.js +1 -1
- package/dist/api/cloudAccount.js +1 -1
- package/dist/api/cloudPlatform.js +1 -1
- package/dist/api/cloudPlatformHorizon.js +1 -1
- package/dist/api/cloudRuntimes.js +1 -1
- package/dist/api/cloudServices.js +1 -1
- package/dist/api/codeShift.d.ts +63 -4
- package/dist/api/codeShift.d.ts.map +1 -1
- package/dist/api/codeShift.js +14 -1
- package/dist/api/codeShift.js.map +1 -1
- package/dist/api/content.js +1 -1
- package/dist/api/dataIntegration.js +1 -1
- package/dist/api/discover.js +1 -1
- package/dist/api/genAiInference.js +1 -1
- package/dist/api/insights.js +1 -1
- package/dist/api/notification.js +1 -1
- package/dist/api/secrets.js +1 -1
- package/dist/api/serviceCatalog.js +1 -1
- package/dist/api/workspace-ai.js +1 -1
- package/dist/api/workspace.js +1 -1
- package/dist/api/workspaceManager.js +1 -1
- package/dist/api/workspaceSearchEngine.js +1 -1
- package/dist/client/ai.d.ts.map +1 -1
- package/dist/client/ai.js +84 -14
- package/dist/client/ai.js.map +1 -1
- package/dist/client/code-shift.d.ts +30 -0
- package/dist/client/code-shift.d.ts.map +1 -1
- package/dist/client/code-shift.js +37 -1
- package/dist/client/code-shift.js.map +1 -1
- package/dist/client/types.d.ts +26 -6
- package/dist/client/types.d.ts.map +1 -1
- package/package.json +7 -7
- package/readme.md +1 -1
- package/scripts/generate-apis.ts +134 -134
- package/src/api/account.ts +8368 -8367
- package/src/api/agent-tools.ts +2172 -2169
- package/src/api/agent.ts +1085 -1083
- package/src/api/ai.ts +3388 -3388
- package/src/api/apiManagement.ts +570 -570
- package/src/api/apiRuntime.ts +2103 -2103
- package/src/api/cloudAccount.ts +1239 -1239
- package/src/api/cloudPlatform.ts +927 -927
- package/src/api/cloudPlatformHorizon.ts +2655 -2655
- package/src/api/cloudRuntimes.ts +2043 -2043
- package/src/api/cloudServices.ts +1445 -1445
- package/src/api/codeShift.ts +3567 -3481
- package/src/api/content.ts +9785 -9785
- package/src/api/dataIntegration.ts +1657 -1657
- package/src/api/discover.ts +435 -435
- package/src/api/eventBus.ts +171 -171
- package/src/api/genAiInference.ts +603 -603
- package/src/api/insights.ts +310 -310
- package/src/api/notification.ts +336 -334
- package/src/api/secrets.ts +342 -342
- package/src/api/serviceCatalog.ts +2908 -2908
- package/src/api/workflows.ts +1669 -1669
- package/src/api/workspace-ai.ts +677 -677
- package/src/api/workspace.ts +5889 -5889
- package/src/api/workspaceManager.ts +2951 -2951
- package/src/api/workspaceSearchEngine.ts +153 -153
- package/src/api-addresses.ts +120 -120
- package/src/apis-itau.json +225 -225
- package/src/apis.json +225 -225
- package/src/client/account.ts +902 -902
- package/src/client/agent-tools.ts +210 -210
- package/src/client/agent.ts +81 -81
- package/src/client/ai.ts +469 -395
- package/src/client/api-management.ts +40 -40
- package/src/client/cloud-account.ts +70 -70
- package/src/client/cloud-platform-horizon.ts +113 -113
- package/src/client/cloud-platform.ts +163 -163
- package/src/client/cloud-runtimes.ts +129 -129
- package/src/client/cloud-services.ts +94 -94
- package/src/client/code-shift.ts +371 -349
- package/src/client/content.ts +538 -538
- package/src/client/data-integration.ts +191 -191
- package/src/client/discover.ts +89 -89
- package/src/client/event-bus.ts +84 -84
- package/src/client/gen-ai-inference.ts +65 -65
- package/src/client/insights.ts +28 -28
- package/src/client/notification.ts +32 -32
- package/src/client/runtime-manager.ts +76 -76
- package/src/client/secrets.ts +60 -60
- package/src/client/types.ts +398 -377
- package/src/client/workflow.ts +83 -83
- package/src/client/workspace-ai.ts +191 -191
- package/src/client/workspace-manager.ts +564 -564
- package/src/client/workspace-search.ts +39 -39
- package/src/client/workspace.ts +480 -480
- package/src/error/DefaultAPIError.ts +151 -151
- package/src/error/FileUploadError.ts +18 -18
- package/src/error/IgnoredErrorCodes.ts +3 -3
- package/src/error/StackspotAPIError.ts +101 -101
- package/src/error/StreamCanceledError.ts +10 -10
- package/src/error/StreamError.ts +7 -7
- package/src/error/StreamJsonError.ts +10 -10
- package/src/error/dictionary/account.ts +58 -58
- package/src/error/dictionary/action-details.ts +20 -20
- package/src/error/dictionary/action.ts +211 -211
- package/src/error/dictionary/agent-tools.ts +75 -75
- package/src/error/dictionary/ai-inference.ts +28 -28
- package/src/error/dictionary/base.ts +22 -22
- package/src/error/dictionary/cloud-platform.ts +82 -82
- package/src/error/dictionary/cnt-fields.ts +14 -14
- package/src/error/dictionary/cnt.ts +103 -103
- package/src/error/dictionary/code-shift.ts +12 -12
- package/src/error/dictionary/rte.ts +24 -24
- package/src/error/dictionary/rtm.ts +10 -10
- package/src/error/dictionary/secrets.ts +14 -14
- package/src/error/dictionary/workspace-ai.ts +10 -10
- package/src/error/dictionary/workspace-details.ts +15 -15
- package/src/error/dictionary/workspace-fields.ts +10 -10
- package/src/error/dictionary/workspace.ts +209 -209
- package/src/error/types.ts +21 -21
- package/src/index.ts +43 -43
- package/src/network/AutoInfiniteQuery.ts +115 -115
- package/src/network/AutoMutation.ts +27 -27
- package/src/network/AutoOperation.ts +73 -73
- package/src/network/AutoQuery.ts +75 -75
- package/src/network/ManualInfiniteQuery.ts +95 -95
- package/src/network/ManualMutation.ts +40 -40
- package/src/network/ManualOperation.ts +52 -52
- package/src/network/ManualQuery.ts +82 -82
- package/src/network/NetworkClient.ts +167 -167
- package/src/network/ReactQueryNetworkClient.ts +312 -312
- package/src/network/react-query-client.ts +14 -14
- package/src/network/types.ts +294 -294
- package/src/types.ts +1 -1
- package/src/utils/StreamedArray.tsx +146 -146
- package/src/utils/StreamedJson.tsx +166 -166
- package/src/utils/remove-authorization-param.ts +6 -6
- package/src/utils/string.ts +19 -19
- package/src/utils/use-extended-list.ts +80 -80
- package/src/utils/use-streamed-array.ts +17 -17
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +10 -10
|
@@ -1,153 +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
|
-
}
|
|
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/api-addresses.ts
CHANGED
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
import apisItauJson from './apis-itau.json' assert { type: 'json' }
|
|
2
|
-
import apisJson from './apis.json' assert { type: 'json' }
|
|
3
|
-
import { NetworkClient } from './network/NetworkClient'
|
|
4
|
-
import { Env, Tenant } from './network/types'
|
|
5
|
-
|
|
6
|
-
type ApisKeys = keyof typeof apisJson;
|
|
7
|
-
|
|
8
|
-
type ApiConfig = {
|
|
9
|
-
url: Record<Env, string>,
|
|
10
|
-
docs?: string,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type PartialApiConfig = {
|
|
14
|
-
url: Partial<Record<Env, string>>,
|
|
15
|
-
docs?: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type Apis = Record<ApisKeys, ApiConfig>;
|
|
19
|
-
|
|
20
|
-
type PartialApis = Partial<Record<ApisKeys, PartialApiConfig>>;
|
|
21
|
-
|
|
22
|
-
type ApiAddress = {
|
|
23
|
-
[api: string]: string,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let defaultApis: Apis = apisJson;
|
|
27
|
-
let overrideApis: PartialApis = {};
|
|
28
|
-
|
|
29
|
-
const apis: Record<Tenant, Apis> = {
|
|
30
|
-
'stackspot': apisJson,
|
|
31
|
-
'itau': apisItauJson,
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Returns the API catalog for the given tenant.
|
|
36
|
-
*
|
|
37
|
-
* @param tenant The current tenant (e.g., 'stackspot', 'itau').
|
|
38
|
-
* @returns API catalog containing the URLs per environment.
|
|
39
|
-
*/
|
|
40
|
-
export function getApisByTenant(tenant: Tenant) {
|
|
41
|
-
return apis[tenant]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function transformApisToApiAddress(apis: Apis, env: Env): ApiAddress {
|
|
45
|
-
const apiAddress: ApiAddress = {}
|
|
46
|
-
|
|
47
|
-
for (const api in apis) {
|
|
48
|
-
const key = api as ApisKeys
|
|
49
|
-
apiAddress[key] = apis[key].url[env]
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return apiAddress
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Searchs the default APIs configuration for the API object that matches the given baseURL.
|
|
57
|
-
* @param baseUrl the base URL to search.
|
|
58
|
-
* @param candidate the URL of the desired API to find.
|
|
59
|
-
* @returns {boolean} true if the URL is found, otherwise false.
|
|
60
|
-
*/
|
|
61
|
-
function matchesBaseUrl(baseUrl: Record<Env, string>, candidate: Record<Env, string>): boolean {
|
|
62
|
-
const envs: Env[] = ['dev', 'stg', 'prd'];
|
|
63
|
-
|
|
64
|
-
return envs.every(e => {
|
|
65
|
-
if (candidate[e]) {
|
|
66
|
-
return baseUrl[e] === candidate[e];
|
|
67
|
-
}
|
|
68
|
-
return true;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Returns the base URL for the given environment and tenant, applying any overrides if available
|
|
74
|
-
*
|
|
75
|
-
* @param baseURL the default API base URL.
|
|
76
|
-
* @param targetEnv the target environment
|
|
77
|
-
* @param tenant the current tenant.
|
|
78
|
-
* @returns {string} the base URL for the given environment and tenant, applying any overrides if available.
|
|
79
|
-
*/
|
|
80
|
-
export const getBaseUrlByTenantWithOverride = (baseUrl: Record<Env, string>, targetEnv: Env = 'prd', tenant: Tenant = 'stackspot'): string => {
|
|
81
|
-
let matchesApiName: ApisKeys | null = null;
|
|
82
|
-
|
|
83
|
-
for (const [apiName, config] of Object.entries(defaultApis) as [ApisKeys, ApiConfig][]) {
|
|
84
|
-
if (matchesBaseUrl(baseUrl, config.url)) {
|
|
85
|
-
matchesApiName = apiName;
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!matchesApiName) return ''
|
|
91
|
-
|
|
92
|
-
const overrideUrl = overrideApis[matchesApiName]?.url?.[targetEnv]
|
|
93
|
-
if (overrideUrl) {
|
|
94
|
-
return overrideUrl;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const apis = getApisByTenant(tenant)
|
|
98
|
-
return apis[matchesApiName]?.url?.[targetEnv];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Sets the APIs addresses for override.
|
|
103
|
-
* @param customApis a JSON object containing APIs address to override.
|
|
104
|
-
*/
|
|
105
|
-
export const setApisOverride = (customApis: PartialApis) => {
|
|
106
|
-
overrideApis = customApis;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Sets the default APIs addresses for each environments.
|
|
111
|
-
* @returns {Apis} an object containing APIs URLs grouped by api name and enviroments.
|
|
112
|
-
*/
|
|
113
|
-
export const getApiAddresses = (): Apis => {
|
|
114
|
-
return defaultApis;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export const apiAddresses = () => {
|
|
118
|
-
const env = NetworkClient.getEnv()
|
|
119
|
-
return transformApisToApiAddress(defaultApis, env)
|
|
120
|
-
}
|
|
1
|
+
import apisItauJson from './apis-itau.json' assert { type: 'json' }
|
|
2
|
+
import apisJson from './apis.json' assert { type: 'json' }
|
|
3
|
+
import { NetworkClient } from './network/NetworkClient'
|
|
4
|
+
import { Env, Tenant } from './network/types'
|
|
5
|
+
|
|
6
|
+
type ApisKeys = keyof typeof apisJson;
|
|
7
|
+
|
|
8
|
+
type ApiConfig = {
|
|
9
|
+
url: Record<Env, string>,
|
|
10
|
+
docs?: string,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type PartialApiConfig = {
|
|
14
|
+
url: Partial<Record<Env, string>>,
|
|
15
|
+
docs?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type Apis = Record<ApisKeys, ApiConfig>;
|
|
19
|
+
|
|
20
|
+
type PartialApis = Partial<Record<ApisKeys, PartialApiConfig>>;
|
|
21
|
+
|
|
22
|
+
type ApiAddress = {
|
|
23
|
+
[api: string]: string,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let defaultApis: Apis = apisJson;
|
|
27
|
+
let overrideApis: PartialApis = {};
|
|
28
|
+
|
|
29
|
+
const apis: Record<Tenant, Apis> = {
|
|
30
|
+
'stackspot': apisJson,
|
|
31
|
+
'itau': apisItauJson,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Returns the API catalog for the given tenant.
|
|
36
|
+
*
|
|
37
|
+
* @param tenant The current tenant (e.g., 'stackspot', 'itau').
|
|
38
|
+
* @returns API catalog containing the URLs per environment.
|
|
39
|
+
*/
|
|
40
|
+
export function getApisByTenant(tenant: Tenant) {
|
|
41
|
+
return apis[tenant]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function transformApisToApiAddress(apis: Apis, env: Env): ApiAddress {
|
|
45
|
+
const apiAddress: ApiAddress = {}
|
|
46
|
+
|
|
47
|
+
for (const api in apis) {
|
|
48
|
+
const key = api as ApisKeys
|
|
49
|
+
apiAddress[key] = apis[key].url[env]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return apiAddress
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Searchs the default APIs configuration for the API object that matches the given baseURL.
|
|
57
|
+
* @param baseUrl the base URL to search.
|
|
58
|
+
* @param candidate the URL of the desired API to find.
|
|
59
|
+
* @returns {boolean} true if the URL is found, otherwise false.
|
|
60
|
+
*/
|
|
61
|
+
function matchesBaseUrl(baseUrl: Record<Env, string>, candidate: Record<Env, string>): boolean {
|
|
62
|
+
const envs: Env[] = ['dev', 'stg', 'prd'];
|
|
63
|
+
|
|
64
|
+
return envs.every(e => {
|
|
65
|
+
if (candidate[e]) {
|
|
66
|
+
return baseUrl[e] === candidate[e];
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Returns the base URL for the given environment and tenant, applying any overrides if available
|
|
74
|
+
*
|
|
75
|
+
* @param baseURL the default API base URL.
|
|
76
|
+
* @param targetEnv the target environment
|
|
77
|
+
* @param tenant the current tenant.
|
|
78
|
+
* @returns {string} the base URL for the given environment and tenant, applying any overrides if available.
|
|
79
|
+
*/
|
|
80
|
+
export const getBaseUrlByTenantWithOverride = (baseUrl: Record<Env, string>, targetEnv: Env = 'prd', tenant: Tenant = 'stackspot'): string => {
|
|
81
|
+
let matchesApiName: ApisKeys | null = null;
|
|
82
|
+
|
|
83
|
+
for (const [apiName, config] of Object.entries(defaultApis) as [ApisKeys, ApiConfig][]) {
|
|
84
|
+
if (matchesBaseUrl(baseUrl, config.url)) {
|
|
85
|
+
matchesApiName = apiName;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!matchesApiName) return ''
|
|
91
|
+
|
|
92
|
+
const overrideUrl = overrideApis[matchesApiName]?.url?.[targetEnv]
|
|
93
|
+
if (overrideUrl) {
|
|
94
|
+
return overrideUrl;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const apis = getApisByTenant(tenant)
|
|
98
|
+
return apis[matchesApiName]?.url?.[targetEnv];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Sets the APIs addresses for override.
|
|
103
|
+
* @param customApis a JSON object containing APIs address to override.
|
|
104
|
+
*/
|
|
105
|
+
export const setApisOverride = (customApis: PartialApis) => {
|
|
106
|
+
overrideApis = customApis;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Sets the default APIs addresses for each environments.
|
|
111
|
+
* @returns {Apis} an object containing APIs URLs grouped by api name and enviroments.
|
|
112
|
+
*/
|
|
113
|
+
export const getApiAddresses = (): Apis => {
|
|
114
|
+
return defaultApis;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const apiAddresses = () => {
|
|
118
|
+
const env = NetworkClient.getEnv()
|
|
119
|
+
return transformApisToApiAddress(defaultApis, env)
|
|
120
|
+
}
|