@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.
- package/CHANGELOG.md +2419 -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/code-shift.d.ts +22 -0
- package/dist/client/code-shift.d.ts.map +1 -1
- package/dist/client/code-shift.js +28 -1
- package/dist/client/code-shift.js.map +1 -1
- package/package.json +6 -6
- package/scripts/generate-apis.ts +134 -134
- package/src/api/account.ts +8367 -8367
- package/src/api/agent-tools.ts +2169 -2169
- package/src/api/agent.ts +1083 -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 +334 -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 +395 -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 +364 -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 +377 -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
package/src/network/types.ts
CHANGED
|
@@ -1,294 +1,294 @@
|
|
|
1
|
-
import type { RequestOpts } from '@oazapfts/runtime'
|
|
2
|
-
import { Session } from '@stack-spot/auth'
|
|
3
|
-
import { InfiniteData, MutateOptions, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from '@tanstack/react-query'
|
|
4
|
-
import { ServerSentEventMessage } from 'fetch-event-stream'
|
|
5
|
-
import { StackspotAPIError } from '../error/StackspotAPIError'
|
|
6
|
-
|
|
7
|
-
export interface SessionManager {
|
|
8
|
-
hasSession(): boolean,
|
|
9
|
-
endSession(): void,
|
|
10
|
-
getSession(): Session,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type Tenant = 'stackspot' | 'itau'
|
|
14
|
-
|
|
15
|
-
export type Env = 'dev' | 'stg' | 'prd'
|
|
16
|
-
|
|
17
|
-
export type HTTPMethod = 'post' | 'patch' | 'delete' | 'put' | 'get'
|
|
18
|
-
|
|
19
|
-
export type FetchEventStream = AsyncGenerator<ServerSentEventMessage, void, unknown>
|
|
20
|
-
|
|
21
|
-
export interface OperationConfig<Args extends [AbortSignal, Record<string, any>] | [AbortSignal], Result> {
|
|
22
|
-
/**
|
|
23
|
-
* The operation name. To be used as key in React Query.
|
|
24
|
-
*/
|
|
25
|
-
name: string,
|
|
26
|
-
/**
|
|
27
|
-
* The function to run once the operation is called.
|
|
28
|
-
* @param abortSignal the AbortSignal to pass to any request made.
|
|
29
|
-
* @param variables if this operation accepts variables, the second parameter is the variables object.
|
|
30
|
-
* @returns the operation result (this should not be a Response object, but it could be its body).
|
|
31
|
-
*/
|
|
32
|
-
request: (...args: Args) => Promise<Result>,
|
|
33
|
-
/**
|
|
34
|
-
* The function to run once one asks if the operation is allowed.
|
|
35
|
-
* @param variables if this operation accepts variables, the single parameter is the variables object.
|
|
36
|
-
* @returns a promise that resolves to true if the operation is allowed and false otherwise.
|
|
37
|
-
*/
|
|
38
|
-
permission: (...args: Args extends [AbortSignal] ? [] : [Args[1]]) => Promise<boolean>,
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export interface InfiniteQueryOptions<Variables, Result, PageParamName extends keyof Variables, Accumulator extends keyof Result | ''> {
|
|
43
|
-
/**
|
|
44
|
-
* The name of the variable that controls the current page.
|
|
45
|
-
*/
|
|
46
|
-
pageParamName: PageParamName,
|
|
47
|
-
/**
|
|
48
|
-
* The name of the property in the Result that contains the items of a page. If the result itself is the array of items, use an empty
|
|
49
|
-
* string ('').
|
|
50
|
-
*/
|
|
51
|
-
accumulator?: Accumulator,
|
|
52
|
-
/**
|
|
53
|
-
* The initial value for page variable.
|
|
54
|
-
*/
|
|
55
|
-
initialPageParam: Variables[PageParamName],
|
|
56
|
-
/**
|
|
57
|
-
* Some defaults to be used when a variable is not specified.
|
|
58
|
-
*/
|
|
59
|
-
defaultVariables?: Partial<Variables>,
|
|
60
|
-
/**
|
|
61
|
-
* A function that determines the value of the page variable in order to get the next page.
|
|
62
|
-
* @param context the current context with the variables and page details.
|
|
63
|
-
* @returns undefined or null if there are no more pages. The next value for the page variable otherwise.
|
|
64
|
-
*/
|
|
65
|
-
getNextPageParam: (context: {
|
|
66
|
-
/**
|
|
67
|
-
* the original set of variables passed to the hook `useInfiniteQuery`.
|
|
68
|
-
*/
|
|
69
|
-
variables: Variables,
|
|
70
|
-
/**
|
|
71
|
-
* the last page Result.
|
|
72
|
-
*/
|
|
73
|
-
lastPage: Result,
|
|
74
|
-
/**
|
|
75
|
-
* the Results of each page.
|
|
76
|
-
*/
|
|
77
|
-
allPages: Result[],
|
|
78
|
-
/**
|
|
79
|
-
* the value of the page variable used to retrieve the last page.
|
|
80
|
-
*/
|
|
81
|
-
lastPageParam: Variables[PageParamName],
|
|
82
|
-
/**
|
|
83
|
-
* the values of the page variable for requesting each of the pages.
|
|
84
|
-
*/
|
|
85
|
-
allPageParams: Variables[PageParamName][],
|
|
86
|
-
}) => Variables[PageParamName] | undefined | null,
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface FullOperationConfig<
|
|
90
|
-
Args extends [AbortSignal, Record<string, any>] | [AbortSignal], Result
|
|
91
|
-
> extends OperationConfig<Args, Result> {
|
|
92
|
-
/**
|
|
93
|
-
* The name of the API where this operation is called: used for composing a query key.
|
|
94
|
-
*/
|
|
95
|
-
apiName: string,
|
|
96
|
-
transformError: (error: any) => StackspotAPIError,
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export type InfiniteQueryConfig<
|
|
100
|
-
Variables extends Record<string, any>,
|
|
101
|
-
Result,
|
|
102
|
-
PageParamName extends keyof Variables,
|
|
103
|
-
Accumulator extends keyof Result | '',
|
|
104
|
-
> = OperationConfig<[AbortSignal, Variables], Result> & InfiniteQueryOptions<Variables, Result, PageParamName, Accumulator>
|
|
105
|
-
|
|
106
|
-
export interface OperationObject<Variables> {
|
|
107
|
-
/**
|
|
108
|
-
* Checks if this operation is allowed for the user currently logged in.
|
|
109
|
-
* @param variables the variables for the operation, if a required url parameter is not provided, it's replaced by a default string.
|
|
110
|
-
* @returns a promise that resolves to true if the operation is allowed or false otherwise.
|
|
111
|
-
* @throws `StackspotAPIError`
|
|
112
|
-
*/
|
|
113
|
-
isAllowed: (...args: Variables extends void ? [] : [variables?: Partial<Variables>]) => Promise<boolean>,
|
|
114
|
-
/**
|
|
115
|
-
* Same as `isAllowed`, but a React Hook instead.
|
|
116
|
-
* @param args if this operation accepts variables, the first argument should be the variables and the second the query options
|
|
117
|
-
* (optional). If it doesn't accept variables, the single optional argument must be the query options. Moreover, if a required url
|
|
118
|
-
* parameter is not provided, it's replaced by a default string.
|
|
119
|
-
* @returns an array with 4 items:
|
|
120
|
-
* - [0]: true if allowed, false if not allowed, undefined if not fetched.
|
|
121
|
-
* - [1]: true if pending, false otherwise.
|
|
122
|
-
* - [2]: a StackspotAPIError if an error happens, null or undefined otherwise.
|
|
123
|
-
* - [3]: the original UseQueryResult object, from ReactQuery.
|
|
124
|
-
*/
|
|
125
|
-
useAllowed: (
|
|
126
|
-
...args: Variables extends void
|
|
127
|
-
? [options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>]
|
|
128
|
-
: [variables?: Partial<Variables>, options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>]
|
|
129
|
-
) => Readonly<[boolean | undefined, boolean, StackspotAPIError | null | undefined, UseQueryResult<boolean, StackspotAPIError>]>,
|
|
130
|
-
/**
|
|
131
|
-
* Gets the key for the query used to verify if this operation is allowed.
|
|
132
|
-
*
|
|
133
|
-
* Attention: invalidating this key won't clear the cache, since the `@stack-spot/opa` library doesn't support individual cache
|
|
134
|
-
* invalidation.
|
|
135
|
-
* @param args if this operation accepts variables, the first argument should be the variables and the second the query options
|
|
136
|
-
* (optional). If it doesn't accept variables, the single optional argument must be the query options. Moreover, if a required url
|
|
137
|
-
* parameter is not provided, it's replaced by a default string.
|
|
138
|
-
* @returns the query key.
|
|
139
|
-
*/
|
|
140
|
-
getPermissionKey: (...args: Variables extends void ? [] : [variables?: Partial<Variables>]) => any[],
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export type UseQueryObjectOptions<Result> = Omit<UseQueryOptions<Result, StackspotAPIError>, 'queryFn' | 'queryKey'>
|
|
144
|
-
|
|
145
|
-
export interface QueryObject<Variables, Result> extends OperationObject<Variables> {
|
|
146
|
-
/**
|
|
147
|
-
* Runs the query operation.
|
|
148
|
-
* @param variables the request variables if this query accepts variables.
|
|
149
|
-
* @returns a Promise with the response data
|
|
150
|
-
* @throws `StackspotAPIError`
|
|
151
|
-
*/
|
|
152
|
-
query: (...args: Variables extends void ? [] : [variables: Variables]) => Promise<Result>,
|
|
153
|
-
/**
|
|
154
|
-
* Same as `query`, but, instead of an async function, this is a React Hook that expects a React Suspense environment.
|
|
155
|
-
*
|
|
156
|
-
* If you want a hook that performs a stateful query instead of relying in Suspense, call `useStatefulQuery` instead.
|
|
157
|
-
*
|
|
158
|
-
* @param args if this query accepts variables, the first argument should be the variables and the second the query options
|
|
159
|
-
* (optional). If it doesn't accept variables, the single optional argument must be the query options.
|
|
160
|
-
* @returns the response data.
|
|
161
|
-
* @throws `StackspotAPIError`
|
|
162
|
-
* @throws `Promise<Result>`
|
|
163
|
-
*/
|
|
164
|
-
useQuery: (
|
|
165
|
-
...args: Variables extends void
|
|
166
|
-
? [options?: UseQueryObjectOptions<Result>]
|
|
167
|
-
: [variables: Variables, options?: UseQueryObjectOptions<Result>]
|
|
168
|
-
) => Result,
|
|
169
|
-
/**
|
|
170
|
-
* Same as `query`, but a React Hook instead.
|
|
171
|
-
* @param args if this query accepts variables, the first argument should be the variables and the second the query options
|
|
172
|
-
* (optional). If it doesn't accept variables, the single optional argument must be the query options.
|
|
173
|
-
* @returns an array with 4 items:
|
|
174
|
-
* - [0]: the response data or undefined if not fetched.
|
|
175
|
-
* - [1]: true if pending, false otherwise.
|
|
176
|
-
* - [2]: a StackspotAPIError if an error happens, null or undefined otherwise.
|
|
177
|
-
* - [3]: the original UseQueryResult object, from ReactQuery.
|
|
178
|
-
*/
|
|
179
|
-
useStatefulQuery: (
|
|
180
|
-
...args: Variables extends void
|
|
181
|
-
? [options?: UseQueryObjectOptions<Result>]
|
|
182
|
-
: [variables: Variables, options?: UseQueryObjectOptions<Result>]
|
|
183
|
-
) => Readonly<[Result | undefined, boolean, StackspotAPIError | null | undefined, UseQueryResult<Result, StackspotAPIError>]>,
|
|
184
|
-
/**
|
|
185
|
-
* Invalidates the cache for this query. A specific query can be invalidated by passing an argument (variables).
|
|
186
|
-
* @param variables if this query accepts variables, a query with specific variables can be invalidated.
|
|
187
|
-
* @returns a promise that resolves once the cache is invalidated.
|
|
188
|
-
*/
|
|
189
|
-
invalidate: (...args: Variables extends void ? [] : [variables?: Partial<Variables>]) => Promise<void>,
|
|
190
|
-
/**
|
|
191
|
-
* Gets the key for this query.
|
|
192
|
-
* @param variables the variables for the query.
|
|
193
|
-
* @returns the query key.
|
|
194
|
-
*/
|
|
195
|
-
getKey: (...args: Variables extends void ? [] : [variables?: Partial<Variables>]) => any[],
|
|
196
|
-
/**
|
|
197
|
-
* Cancels the query if it hasn't finished yet.
|
|
198
|
-
*
|
|
199
|
-
* @param variables the variables for the operation. If not provided, this will cancel all requests in progress for this query.
|
|
200
|
-
*/
|
|
201
|
-
cancel: (variables?: Partial<Variables>) => void,
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export type UseInfiniteQueryObjectOptions<Result> = Omit<
|
|
205
|
-
UseInfiniteQueryOptions<Result, StackspotAPIError>,
|
|
206
|
-
'queryFn' | 'queryKey' | 'getNextPageParam' | 'initialPageParam'
|
|
207
|
-
>
|
|
208
|
-
|
|
209
|
-
export interface InfiniteQueryObject<Variables, Result, Accumulator extends keyof Result | ''> extends QueryObject<Variables, Result> {
|
|
210
|
-
/**
|
|
211
|
-
* Builds up a list with the result of multiple pages. This relies on React Suspense for error and first-loading feedbacks.
|
|
212
|
-
*
|
|
213
|
-
* Equivalent to React Query's `useSuspenseInfiniteQuery`.
|
|
214
|
-
* @param variables the variables for the query.
|
|
215
|
-
* @param options the options for the query.
|
|
216
|
-
* @returns an array with 2 items:
|
|
217
|
-
* - [0]: the list of items.
|
|
218
|
-
* - [1]: the original UseInfiniteQueryResult object, from ReactQuery.
|
|
219
|
-
*/
|
|
220
|
-
useInfiniteQuery: (
|
|
221
|
-
...args: Partial<Variables> extends Variables
|
|
222
|
-
? [variables?: Variables, options?: UseInfiniteQueryObjectOptions<Result>]
|
|
223
|
-
: [variables: Variables, options?: UseInfiniteQueryObjectOptions<Result>]
|
|
224
|
-
) => Readonly<[
|
|
225
|
-
(Accumulator extends keyof Result ? Result[Accumulator] : Result),
|
|
226
|
-
UseInfiniteQueryResult<InfiniteData<Result>, StackspotAPIError>,
|
|
227
|
-
]>,
|
|
228
|
-
/**
|
|
229
|
-
* Builds up a list with the result of multiple pages.
|
|
230
|
-
*
|
|
231
|
-
* Equivalent to React Query's `useInfiniteQuery`.
|
|
232
|
-
* @param variables the variables for the query.
|
|
233
|
-
* @param options the options for the query.
|
|
234
|
-
* @returns an array with 4 items:
|
|
235
|
-
* - [0]: the list of items.
|
|
236
|
-
* - [1]: true if fetching the first page, false otherwise.
|
|
237
|
-
* - [2]: a StackspotAPIError if an error happens, null or undefined otherwise.
|
|
238
|
-
* - [3]: the original UseInfiniteQueryResult object, from ReactQuery.
|
|
239
|
-
*/
|
|
240
|
-
useStatefulInfiniteQuery: (
|
|
241
|
-
...args: Partial<Variables> extends Variables
|
|
242
|
-
? [variables?: Variables, options?: UseInfiniteQueryObjectOptions<Result>]
|
|
243
|
-
: [variables: Variables, options?: UseInfiniteQueryObjectOptions<Result>]
|
|
244
|
-
) => Readonly<[
|
|
245
|
-
(Accumulator extends keyof Result ? Result[Accumulator] : Result) | undefined,
|
|
246
|
-
boolean,
|
|
247
|
-
StackspotAPIError | undefined | null,
|
|
248
|
-
UseInfiniteQueryResult<InfiniteData<Result>, StackspotAPIError>,
|
|
249
|
-
]>,
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export interface AutoQueryObjectParams<Variables, Result> {
|
|
253
|
-
apiName: string,
|
|
254
|
-
fn: ((variables: Variables, opts?: RequestOpts) => Promise<Result>) | ((opts?: RequestOpts) => Promise<Result>),
|
|
255
|
-
onFetchPermission: typeof fetch,
|
|
256
|
-
transformError?: (error: any) => StackspotAPIError,
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export interface MutationObject<Variables, Result> extends OperationObject<Variables> {
|
|
260
|
-
/**
|
|
261
|
-
* Runs the mutation and returns a promise.
|
|
262
|
-
* @param args the variables for the mutation.
|
|
263
|
-
* @returns a promise that resolves to the response's data.
|
|
264
|
-
*/
|
|
265
|
-
mutate: (...args: Variables extends void ? [signal?: AbortSignal] : [variables: Variables, signal?: AbortSignal]) => Promise<Result>,
|
|
266
|
-
/**
|
|
267
|
-
* A React hook equivalent to React Query's `useMutation`. It creates a mutation function and the mutation states.
|
|
268
|
-
* @param options the options for `useMutation`
|
|
269
|
-
* @returns an array with 4 items:
|
|
270
|
-
* - [0]: the mutation function (equivalent to `mutateAsync` from the result of a `useMutation`).
|
|
271
|
-
* - [1]: true if pending, false otherwise.
|
|
272
|
-
* - [2]: a StackspotAPIError if an error happens, undefined otherwise.
|
|
273
|
-
* - [3]: the original UseMutationResult object, from ReactQuery.
|
|
274
|
-
*
|
|
275
|
-
*/
|
|
276
|
-
useMutation: (options?: Omit<UseMutationOptions<Result, StackspotAPIError, Variables>, 'mutationFn'> & { signal?: AbortSignal }) =>
|
|
277
|
-
Readonly<[
|
|
278
|
-
(...args: Variables extends void
|
|
279
|
-
? [options?: MutateOptions<Result, StackspotAPIError>]
|
|
280
|
-
: [variables: Variables, options?: MutateOptions<Result, StackspotAPIError, Variables>]
|
|
281
|
-
) => Promise<Result>,
|
|
282
|
-
boolean,
|
|
283
|
-
StackspotAPIError | undefined,
|
|
284
|
-
UseMutationResult<Result, StackspotAPIError, Variables>,
|
|
285
|
-
]>,
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
export type OperationVariables<T extends Pick<OperationObject<any>, 'isAllowed'>> = T extends Pick<OperationObject<infer R>, 'isAllowed'>
|
|
289
|
-
? R
|
|
290
|
-
: never
|
|
291
|
-
export type OperationResult<T extends { query: (variables?: any) => Promise<any> } | { mutate: (variables?: any) => Promise<any> }> =
|
|
292
|
-
T extends { query: (variables?: any) => Promise<infer R> } ? R : (
|
|
293
|
-
T extends { mutate: (variables?: any) => Promise<infer R> } ? R : never
|
|
294
|
-
)
|
|
1
|
+
import type { RequestOpts } from '@oazapfts/runtime'
|
|
2
|
+
import { Session } from '@stack-spot/auth'
|
|
3
|
+
import { InfiniteData, MutateOptions, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from '@tanstack/react-query'
|
|
4
|
+
import { ServerSentEventMessage } from 'fetch-event-stream'
|
|
5
|
+
import { StackspotAPIError } from '../error/StackspotAPIError'
|
|
6
|
+
|
|
7
|
+
export interface SessionManager {
|
|
8
|
+
hasSession(): boolean,
|
|
9
|
+
endSession(): void,
|
|
10
|
+
getSession(): Session,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type Tenant = 'stackspot' | 'itau'
|
|
14
|
+
|
|
15
|
+
export type Env = 'dev' | 'stg' | 'prd'
|
|
16
|
+
|
|
17
|
+
export type HTTPMethod = 'post' | 'patch' | 'delete' | 'put' | 'get'
|
|
18
|
+
|
|
19
|
+
export type FetchEventStream = AsyncGenerator<ServerSentEventMessage, void, unknown>
|
|
20
|
+
|
|
21
|
+
export interface OperationConfig<Args extends [AbortSignal, Record<string, any>] | [AbortSignal], Result> {
|
|
22
|
+
/**
|
|
23
|
+
* The operation name. To be used as key in React Query.
|
|
24
|
+
*/
|
|
25
|
+
name: string,
|
|
26
|
+
/**
|
|
27
|
+
* The function to run once the operation is called.
|
|
28
|
+
* @param abortSignal the AbortSignal to pass to any request made.
|
|
29
|
+
* @param variables if this operation accepts variables, the second parameter is the variables object.
|
|
30
|
+
* @returns the operation result (this should not be a Response object, but it could be its body).
|
|
31
|
+
*/
|
|
32
|
+
request: (...args: Args) => Promise<Result>,
|
|
33
|
+
/**
|
|
34
|
+
* The function to run once one asks if the operation is allowed.
|
|
35
|
+
* @param variables if this operation accepts variables, the single parameter is the variables object.
|
|
36
|
+
* @returns a promise that resolves to true if the operation is allowed and false otherwise.
|
|
37
|
+
*/
|
|
38
|
+
permission: (...args: Args extends [AbortSignal] ? [] : [Args[1]]) => Promise<boolean>,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
export interface InfiniteQueryOptions<Variables, Result, PageParamName extends keyof Variables, Accumulator extends keyof Result | ''> {
|
|
43
|
+
/**
|
|
44
|
+
* The name of the variable that controls the current page.
|
|
45
|
+
*/
|
|
46
|
+
pageParamName: PageParamName,
|
|
47
|
+
/**
|
|
48
|
+
* The name of the property in the Result that contains the items of a page. If the result itself is the array of items, use an empty
|
|
49
|
+
* string ('').
|
|
50
|
+
*/
|
|
51
|
+
accumulator?: Accumulator,
|
|
52
|
+
/**
|
|
53
|
+
* The initial value for page variable.
|
|
54
|
+
*/
|
|
55
|
+
initialPageParam: Variables[PageParamName],
|
|
56
|
+
/**
|
|
57
|
+
* Some defaults to be used when a variable is not specified.
|
|
58
|
+
*/
|
|
59
|
+
defaultVariables?: Partial<Variables>,
|
|
60
|
+
/**
|
|
61
|
+
* A function that determines the value of the page variable in order to get the next page.
|
|
62
|
+
* @param context the current context with the variables and page details.
|
|
63
|
+
* @returns undefined or null if there are no more pages. The next value for the page variable otherwise.
|
|
64
|
+
*/
|
|
65
|
+
getNextPageParam: (context: {
|
|
66
|
+
/**
|
|
67
|
+
* the original set of variables passed to the hook `useInfiniteQuery`.
|
|
68
|
+
*/
|
|
69
|
+
variables: Variables,
|
|
70
|
+
/**
|
|
71
|
+
* the last page Result.
|
|
72
|
+
*/
|
|
73
|
+
lastPage: Result,
|
|
74
|
+
/**
|
|
75
|
+
* the Results of each page.
|
|
76
|
+
*/
|
|
77
|
+
allPages: Result[],
|
|
78
|
+
/**
|
|
79
|
+
* the value of the page variable used to retrieve the last page.
|
|
80
|
+
*/
|
|
81
|
+
lastPageParam: Variables[PageParamName],
|
|
82
|
+
/**
|
|
83
|
+
* the values of the page variable for requesting each of the pages.
|
|
84
|
+
*/
|
|
85
|
+
allPageParams: Variables[PageParamName][],
|
|
86
|
+
}) => Variables[PageParamName] | undefined | null,
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface FullOperationConfig<
|
|
90
|
+
Args extends [AbortSignal, Record<string, any>] | [AbortSignal], Result
|
|
91
|
+
> extends OperationConfig<Args, Result> {
|
|
92
|
+
/**
|
|
93
|
+
* The name of the API where this operation is called: used for composing a query key.
|
|
94
|
+
*/
|
|
95
|
+
apiName: string,
|
|
96
|
+
transformError: (error: any) => StackspotAPIError,
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type InfiniteQueryConfig<
|
|
100
|
+
Variables extends Record<string, any>,
|
|
101
|
+
Result,
|
|
102
|
+
PageParamName extends keyof Variables,
|
|
103
|
+
Accumulator extends keyof Result | '',
|
|
104
|
+
> = OperationConfig<[AbortSignal, Variables], Result> & InfiniteQueryOptions<Variables, Result, PageParamName, Accumulator>
|
|
105
|
+
|
|
106
|
+
export interface OperationObject<Variables> {
|
|
107
|
+
/**
|
|
108
|
+
* Checks if this operation is allowed for the user currently logged in.
|
|
109
|
+
* @param variables the variables for the operation, if a required url parameter is not provided, it's replaced by a default string.
|
|
110
|
+
* @returns a promise that resolves to true if the operation is allowed or false otherwise.
|
|
111
|
+
* @throws `StackspotAPIError`
|
|
112
|
+
*/
|
|
113
|
+
isAllowed: (...args: Variables extends void ? [] : [variables?: Partial<Variables>]) => Promise<boolean>,
|
|
114
|
+
/**
|
|
115
|
+
* Same as `isAllowed`, but a React Hook instead.
|
|
116
|
+
* @param args if this operation accepts variables, the first argument should be the variables and the second the query options
|
|
117
|
+
* (optional). If it doesn't accept variables, the single optional argument must be the query options. Moreover, if a required url
|
|
118
|
+
* parameter is not provided, it's replaced by a default string.
|
|
119
|
+
* @returns an array with 4 items:
|
|
120
|
+
* - [0]: true if allowed, false if not allowed, undefined if not fetched.
|
|
121
|
+
* - [1]: true if pending, false otherwise.
|
|
122
|
+
* - [2]: a StackspotAPIError if an error happens, null or undefined otherwise.
|
|
123
|
+
* - [3]: the original UseQueryResult object, from ReactQuery.
|
|
124
|
+
*/
|
|
125
|
+
useAllowed: (
|
|
126
|
+
...args: Variables extends void
|
|
127
|
+
? [options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>]
|
|
128
|
+
: [variables?: Partial<Variables>, options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>]
|
|
129
|
+
) => Readonly<[boolean | undefined, boolean, StackspotAPIError | null | undefined, UseQueryResult<boolean, StackspotAPIError>]>,
|
|
130
|
+
/**
|
|
131
|
+
* Gets the key for the query used to verify if this operation is allowed.
|
|
132
|
+
*
|
|
133
|
+
* Attention: invalidating this key won't clear the cache, since the `@stack-spot/opa` library doesn't support individual cache
|
|
134
|
+
* invalidation.
|
|
135
|
+
* @param args if this operation accepts variables, the first argument should be the variables and the second the query options
|
|
136
|
+
* (optional). If it doesn't accept variables, the single optional argument must be the query options. Moreover, if a required url
|
|
137
|
+
* parameter is not provided, it's replaced by a default string.
|
|
138
|
+
* @returns the query key.
|
|
139
|
+
*/
|
|
140
|
+
getPermissionKey: (...args: Variables extends void ? [] : [variables?: Partial<Variables>]) => any[],
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type UseQueryObjectOptions<Result> = Omit<UseQueryOptions<Result, StackspotAPIError>, 'queryFn' | 'queryKey'>
|
|
144
|
+
|
|
145
|
+
export interface QueryObject<Variables, Result> extends OperationObject<Variables> {
|
|
146
|
+
/**
|
|
147
|
+
* Runs the query operation.
|
|
148
|
+
* @param variables the request variables if this query accepts variables.
|
|
149
|
+
* @returns a Promise with the response data
|
|
150
|
+
* @throws `StackspotAPIError`
|
|
151
|
+
*/
|
|
152
|
+
query: (...args: Variables extends void ? [] : [variables: Variables]) => Promise<Result>,
|
|
153
|
+
/**
|
|
154
|
+
* Same as `query`, but, instead of an async function, this is a React Hook that expects a React Suspense environment.
|
|
155
|
+
*
|
|
156
|
+
* If you want a hook that performs a stateful query instead of relying in Suspense, call `useStatefulQuery` instead.
|
|
157
|
+
*
|
|
158
|
+
* @param args if this query accepts variables, the first argument should be the variables and the second the query options
|
|
159
|
+
* (optional). If it doesn't accept variables, the single optional argument must be the query options.
|
|
160
|
+
* @returns the response data.
|
|
161
|
+
* @throws `StackspotAPIError`
|
|
162
|
+
* @throws `Promise<Result>`
|
|
163
|
+
*/
|
|
164
|
+
useQuery: (
|
|
165
|
+
...args: Variables extends void
|
|
166
|
+
? [options?: UseQueryObjectOptions<Result>]
|
|
167
|
+
: [variables: Variables, options?: UseQueryObjectOptions<Result>]
|
|
168
|
+
) => Result,
|
|
169
|
+
/**
|
|
170
|
+
* Same as `query`, but a React Hook instead.
|
|
171
|
+
* @param args if this query accepts variables, the first argument should be the variables and the second the query options
|
|
172
|
+
* (optional). If it doesn't accept variables, the single optional argument must be the query options.
|
|
173
|
+
* @returns an array with 4 items:
|
|
174
|
+
* - [0]: the response data or undefined if not fetched.
|
|
175
|
+
* - [1]: true if pending, false otherwise.
|
|
176
|
+
* - [2]: a StackspotAPIError if an error happens, null or undefined otherwise.
|
|
177
|
+
* - [3]: the original UseQueryResult object, from ReactQuery.
|
|
178
|
+
*/
|
|
179
|
+
useStatefulQuery: (
|
|
180
|
+
...args: Variables extends void
|
|
181
|
+
? [options?: UseQueryObjectOptions<Result>]
|
|
182
|
+
: [variables: Variables, options?: UseQueryObjectOptions<Result>]
|
|
183
|
+
) => Readonly<[Result | undefined, boolean, StackspotAPIError | null | undefined, UseQueryResult<Result, StackspotAPIError>]>,
|
|
184
|
+
/**
|
|
185
|
+
* Invalidates the cache for this query. A specific query can be invalidated by passing an argument (variables).
|
|
186
|
+
* @param variables if this query accepts variables, a query with specific variables can be invalidated.
|
|
187
|
+
* @returns a promise that resolves once the cache is invalidated.
|
|
188
|
+
*/
|
|
189
|
+
invalidate: (...args: Variables extends void ? [] : [variables?: Partial<Variables>]) => Promise<void>,
|
|
190
|
+
/**
|
|
191
|
+
* Gets the key for this query.
|
|
192
|
+
* @param variables the variables for the query.
|
|
193
|
+
* @returns the query key.
|
|
194
|
+
*/
|
|
195
|
+
getKey: (...args: Variables extends void ? [] : [variables?: Partial<Variables>]) => any[],
|
|
196
|
+
/**
|
|
197
|
+
* Cancels the query if it hasn't finished yet.
|
|
198
|
+
*
|
|
199
|
+
* @param variables the variables for the operation. If not provided, this will cancel all requests in progress for this query.
|
|
200
|
+
*/
|
|
201
|
+
cancel: (variables?: Partial<Variables>) => void,
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export type UseInfiniteQueryObjectOptions<Result> = Omit<
|
|
205
|
+
UseInfiniteQueryOptions<Result, StackspotAPIError>,
|
|
206
|
+
'queryFn' | 'queryKey' | 'getNextPageParam' | 'initialPageParam'
|
|
207
|
+
>
|
|
208
|
+
|
|
209
|
+
export interface InfiniteQueryObject<Variables, Result, Accumulator extends keyof Result | ''> extends QueryObject<Variables, Result> {
|
|
210
|
+
/**
|
|
211
|
+
* Builds up a list with the result of multiple pages. This relies on React Suspense for error and first-loading feedbacks.
|
|
212
|
+
*
|
|
213
|
+
* Equivalent to React Query's `useSuspenseInfiniteQuery`.
|
|
214
|
+
* @param variables the variables for the query.
|
|
215
|
+
* @param options the options for the query.
|
|
216
|
+
* @returns an array with 2 items:
|
|
217
|
+
* - [0]: the list of items.
|
|
218
|
+
* - [1]: the original UseInfiniteQueryResult object, from ReactQuery.
|
|
219
|
+
*/
|
|
220
|
+
useInfiniteQuery: (
|
|
221
|
+
...args: Partial<Variables> extends Variables
|
|
222
|
+
? [variables?: Variables, options?: UseInfiniteQueryObjectOptions<Result>]
|
|
223
|
+
: [variables: Variables, options?: UseInfiniteQueryObjectOptions<Result>]
|
|
224
|
+
) => Readonly<[
|
|
225
|
+
(Accumulator extends keyof Result ? Result[Accumulator] : Result),
|
|
226
|
+
UseInfiniteQueryResult<InfiniteData<Result>, StackspotAPIError>,
|
|
227
|
+
]>,
|
|
228
|
+
/**
|
|
229
|
+
* Builds up a list with the result of multiple pages.
|
|
230
|
+
*
|
|
231
|
+
* Equivalent to React Query's `useInfiniteQuery`.
|
|
232
|
+
* @param variables the variables for the query.
|
|
233
|
+
* @param options the options for the query.
|
|
234
|
+
* @returns an array with 4 items:
|
|
235
|
+
* - [0]: the list of items.
|
|
236
|
+
* - [1]: true if fetching the first page, false otherwise.
|
|
237
|
+
* - [2]: a StackspotAPIError if an error happens, null or undefined otherwise.
|
|
238
|
+
* - [3]: the original UseInfiniteQueryResult object, from ReactQuery.
|
|
239
|
+
*/
|
|
240
|
+
useStatefulInfiniteQuery: (
|
|
241
|
+
...args: Partial<Variables> extends Variables
|
|
242
|
+
? [variables?: Variables, options?: UseInfiniteQueryObjectOptions<Result>]
|
|
243
|
+
: [variables: Variables, options?: UseInfiniteQueryObjectOptions<Result>]
|
|
244
|
+
) => Readonly<[
|
|
245
|
+
(Accumulator extends keyof Result ? Result[Accumulator] : Result) | undefined,
|
|
246
|
+
boolean,
|
|
247
|
+
StackspotAPIError | undefined | null,
|
|
248
|
+
UseInfiniteQueryResult<InfiniteData<Result>, StackspotAPIError>,
|
|
249
|
+
]>,
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export interface AutoQueryObjectParams<Variables, Result> {
|
|
253
|
+
apiName: string,
|
|
254
|
+
fn: ((variables: Variables, opts?: RequestOpts) => Promise<Result>) | ((opts?: RequestOpts) => Promise<Result>),
|
|
255
|
+
onFetchPermission: typeof fetch,
|
|
256
|
+
transformError?: (error: any) => StackspotAPIError,
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export interface MutationObject<Variables, Result> extends OperationObject<Variables> {
|
|
260
|
+
/**
|
|
261
|
+
* Runs the mutation and returns a promise.
|
|
262
|
+
* @param args the variables for the mutation.
|
|
263
|
+
* @returns a promise that resolves to the response's data.
|
|
264
|
+
*/
|
|
265
|
+
mutate: (...args: Variables extends void ? [signal?: AbortSignal] : [variables: Variables, signal?: AbortSignal]) => Promise<Result>,
|
|
266
|
+
/**
|
|
267
|
+
* A React hook equivalent to React Query's `useMutation`. It creates a mutation function and the mutation states.
|
|
268
|
+
* @param options the options for `useMutation`
|
|
269
|
+
* @returns an array with 4 items:
|
|
270
|
+
* - [0]: the mutation function (equivalent to `mutateAsync` from the result of a `useMutation`).
|
|
271
|
+
* - [1]: true if pending, false otherwise.
|
|
272
|
+
* - [2]: a StackspotAPIError if an error happens, undefined otherwise.
|
|
273
|
+
* - [3]: the original UseMutationResult object, from ReactQuery.
|
|
274
|
+
*
|
|
275
|
+
*/
|
|
276
|
+
useMutation: (options?: Omit<UseMutationOptions<Result, StackspotAPIError, Variables>, 'mutationFn'> & { signal?: AbortSignal }) =>
|
|
277
|
+
Readonly<[
|
|
278
|
+
(...args: Variables extends void
|
|
279
|
+
? [options?: MutateOptions<Result, StackspotAPIError>]
|
|
280
|
+
: [variables: Variables, options?: MutateOptions<Result, StackspotAPIError, Variables>]
|
|
281
|
+
) => Promise<Result>,
|
|
282
|
+
boolean,
|
|
283
|
+
StackspotAPIError | undefined,
|
|
284
|
+
UseMutationResult<Result, StackspotAPIError, Variables>,
|
|
285
|
+
]>,
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export type OperationVariables<T extends Pick<OperationObject<any>, 'isAllowed'>> = T extends Pick<OperationObject<infer R>, 'isAllowed'>
|
|
289
|
+
? R
|
|
290
|
+
: never
|
|
291
|
+
export type OperationResult<T extends { query: (variables?: any) => Promise<any> } | { mutate: (variables?: any) => Promise<any> }> =
|
|
292
|
+
T extends { query: (variables?: any) => Promise<infer R> } ? R : (
|
|
293
|
+
T extends { mutate: (variables?: any) => Promise<infer R> } ? R : never
|
|
294
|
+
)
|
package/src/types.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type StreamingStatus = 'pending' | 'success' | 'error'
|
|
1
|
+
export type StreamingStatus = 'pending' | 'success' | 'error'
|