@unito/integrations-platform-client 0.48.4 → 1.0.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.
@@ -0,0 +1,154 @@
1
+ import * as IntegrationApi from '@unito/integration-api';
2
+ import * as Oazapfts from '@oazapfts/runtime';
3
+ import { HttpError } from '@oazapfts/runtime';
4
+ export { HttpError };
5
+ import { Error } from './api.js';
6
+ /**
7
+ * Provides a type guard for ItemResponse.
8
+ *
9
+ * Return true if object has the shape of an item, false otherwise.
10
+ * @param object
11
+ */
12
+ export declare function isItemResponse(object: unknown): object is Response<IntegrationApi.Item>;
13
+ /**
14
+ * Provides a type guard for ItemSummaryResponse.
15
+ *
16
+ * Return true if object has the shape of an item summary, false otherwise.
17
+ * @param object
18
+ */
19
+ export declare function isItemSummaryResponse(object: unknown): object is Response<IntegrationApi.ItemSummary>;
20
+ /**
21
+ * Provides a type guard for CollectionResponse.
22
+ *
23
+ * Return true if object has the shape of a collection, false otherwise.
24
+ * @param object
25
+ */
26
+ export declare function isCollectionResponse(object: unknown): object is Response<IntegrationApi.Collection>;
27
+ /**
28
+ * Provides a type guard for ErrorResponse.
29
+ *
30
+ * Return true if object has the shape of an error response, false otherwise.
31
+ * @param object
32
+ */
33
+ export declare function isErrorResponse(object: unknown): object is ErrorResponse;
34
+ /**
35
+ * Opt-in optimistic mode.
36
+ *
37
+ * Returns the typed response's data if it's a success, otherwise throws an HttpError.
38
+ *
39
+ * @param response received from the Integrations Platform Client
40
+ * @returns the response's data, typed, if it's a success
41
+ */
42
+ export declare function optimistic<T>(asyncResponse: Promise<Response<T> | ErrorResponse>): Promise<T>;
43
+ type Response<T> = ({
44
+ status: 200;
45
+ } | {
46
+ status: 201;
47
+ } | {
48
+ status: 202;
49
+ } | {
50
+ status: 204;
51
+ }) & {
52
+ data: T;
53
+ headers: Headers;
54
+ };
55
+ type ErrorResponse = ({
56
+ status: 400;
57
+ } | {
58
+ status: 401;
59
+ } | {
60
+ status: 403;
61
+ } | {
62
+ status: 404;
63
+ } | {
64
+ status: 406;
65
+ } | {
66
+ status: 410;
67
+ } | {
68
+ status: 422;
69
+ } | {
70
+ status: 429;
71
+ } | {
72
+ status: 500;
73
+ }) & {
74
+ data: Error;
75
+ headers: Headers;
76
+ };
77
+ /**
78
+ * Wrapper of getProxyGraph that returns a typed response containing an Item upon success.
79
+ *
80
+ * @param xUnitoCredentialId The credential ID to use for the request
81
+ * @param path The path to the item to fetch
82
+ * @param headers The headers to include in the request
83
+ * @param opts Additional options
84
+ * @returns A successful response containing an Item, or an ErrorResponse
85
+ */
86
+ export declare function getProxyGraphItem(xUnitoCredentialId: string, path: string, { xUnitoCorrelationId, xUnitoAdditionalLoggingContext, }?: {
87
+ xUnitoCorrelationId?: string;
88
+ xUnitoAdditionalLoggingContext?: string;
89
+ }, opts?: Oazapfts.RequestOpts): Promise<Response<IntegrationApi.Item> | ErrorResponse>;
90
+ /**
91
+ * Wrapper of getProxyGraph that returns a typed response containing a Collection upon success.
92
+ *
93
+ * @param xUnitoCredentialId The credential ID to use for the request
94
+ * @param path The path to the item to fetch
95
+ * @param headers The headers to include in the request
96
+ * @param opts Additional options
97
+ * @returns A successful response containing an Collection, or an ErrorResponse
98
+ */
99
+ export declare function getProxyGraphCollection(xUnitoCredentialId: string, path: string, { xUnitoCorrelationId, xUnitoAdditionalLoggingContext, }?: {
100
+ xUnitoCorrelationId?: string;
101
+ xUnitoAdditionalLoggingContext?: string;
102
+ }, opts?: Oazapfts.RequestOpts): Promise<Response<IntegrationApi.Collection> | ErrorResponse>;
103
+ /**
104
+ * Wrapper of patchProxyGraph that returns a typed response containing the updated Item upon success.
105
+ *
106
+ * @param xUnitoCredentialId The credential ID to use for the request
107
+ * @param path The path to the item to fetch
108
+ * @param headers The headers to include in the request
109
+ * @param opts Additional options
110
+ * @returns A successful response containing an Item, or an ErrorResponse
111
+ */
112
+ export declare function patchProxyGraphItem(xUnitoCredentialId: string, path: string, body?: object, { xUnitoCorrelationId, xUnitoAdditionalLoggingContext, }?: {
113
+ xUnitoCorrelationId?: string;
114
+ xUnitoAdditionalLoggingContext?: string;
115
+ }, opts?: Oazapfts.RequestOpts): Promise<Response<IntegrationApi.Item> | ErrorResponse>;
116
+ /**
117
+ * Wrapper of postProxyGraph that returns a typed response containing the created ItemSummary upon success.
118
+ *
119
+ * @param xUnitoCredentialId The credential ID to use for the request
120
+ * @param path The path to the item to fetch
121
+ * @param headers The headers to include in the request
122
+ * @param opts Additional options
123
+ * @returns A successful response containing an ItemSummary, or an ErrorResponse
124
+ */
125
+ export declare function postProxyGraphCollection(xUnitoCredentialId: string, path: string, body?: object, { xUnitoCorrelationId, xUnitoAdditionalLoggingContext, }?: {
126
+ xUnitoCorrelationId?: string;
127
+ xUnitoAdditionalLoggingContext?: string;
128
+ }, opts?: Oazapfts.RequestOpts): Promise<Response<IntegrationApi.ItemSummary> | ErrorResponse>;
129
+ /**
130
+ * Wrapper of deleteProxyGraph added for uniformity, doesn't provide much typing help.
131
+ *
132
+ * @param xUnitoCredentialId The credential ID to use for the request
133
+ * @param path The path to the item to fetch
134
+ * @param headers The headers to include in the request
135
+ * @param opts Additional options
136
+ */
137
+ export declare function deleteProxyGraphItem(xUnitoCredentialId: string, path: string, { xUnitoCorrelationId, xUnitoAdditionalLoggingContext, }?: {
138
+ xUnitoCorrelationId?: string;
139
+ xUnitoAdditionalLoggingContext?: string;
140
+ }, opts?: Oazapfts.RequestOpts): Promise<void>;
141
+ /**
142
+ * Call an integration's graph and returns the fetch response directly to enable streaming of the body as it comes in.
143
+ *
144
+ * @param xUnitoCredentialId The credential ID to use for the request
145
+ * @param path The path to the item to fetch
146
+ * @param headers Base headers to add to the request
147
+ * @param additionalHeaders Additional headers to add to the request
148
+ * @returns fetch's response
149
+ */
150
+ export declare function fetchProxyGraph(xUnitoCredentialId: string, path: string, { xUnitoCorrelationId, xUnitoAdditionalLoggingContext, accept, }?: {
151
+ xUnitoCorrelationId?: string;
152
+ xUnitoAdditionalLoggingContext?: string;
153
+ accept?: string;
154
+ }, init?: RequestInit): Promise<globalThis.Response>;
@@ -0,0 +1,182 @@
1
+ // MANUAL ADDONS
2
+ import * as Oazapfts from '@oazapfts/runtime';
3
+ import * as QS from '@oazapfts/runtime/query';
4
+ import { HttpError } from '@oazapfts/runtime';
5
+ export { HttpError };
6
+ import { defaults, getProxyGraph, patchProxyGraph, postProxyGraph, deleteProxyGraph } from './api.js';
7
+ const oazapfts = Oazapfts.runtime(defaults);
8
+ /**
9
+ * Provides a type guard for ItemResponse.
10
+ *
11
+ * Return true if object has the shape of an item, false otherwise.
12
+ * @param object
13
+ */
14
+ export function isItemResponse(object) {
15
+ const data = object.data;
16
+ return !!object && !!data && typeof data === 'object' && 'fields' in data && 'relations' in data;
17
+ }
18
+ /**
19
+ * Provides a type guard for ItemSummaryResponse.
20
+ *
21
+ * Return true if object has the shape of an item summary, false otherwise.
22
+ * @param object
23
+ */
24
+ export function isItemSummaryResponse(object) {
25
+ const data = object.data;
26
+ return !!object && !!data && typeof data === 'object' && 'path' in data;
27
+ }
28
+ /**
29
+ * Provides a type guard for CollectionResponse.
30
+ *
31
+ * Return true if object has the shape of a collection, false otherwise.
32
+ * @param object
33
+ */
34
+ export function isCollectionResponse(object) {
35
+ const data = object.data;
36
+ return !!object && !!data && typeof data === 'object' && 'info' in data && 'data' in data && Array.isArray(data.data);
37
+ }
38
+ /**
39
+ * Provides a type guard for ErrorResponse.
40
+ *
41
+ * Return true if object has the shape of an error response, false otherwise.
42
+ * @param object
43
+ */
44
+ export function isErrorResponse(object) {
45
+ const status = object.status;
46
+ return !!object && typeof object === 'object' && status && status >= 400 && 'data' in object && 'headers' in object;
47
+ }
48
+ /**
49
+ * Opt-in optimistic mode.
50
+ *
51
+ * Returns the typed response's data if it's a success, otherwise throws an HttpError.
52
+ *
53
+ * @param response received from the Integrations Platform Client
54
+ * @returns the response's data, typed, if it's a success
55
+ */
56
+ export async function optimistic(asyncResponse) {
57
+ const response = await asyncResponse;
58
+ if (isErrorResponse(response)) {
59
+ throw new HttpError(response.status, response.data, response.headers);
60
+ }
61
+ return response.data;
62
+ }
63
+ /**
64
+ * Wrapper of getProxyGraph that returns a typed response containing an Item upon success.
65
+ *
66
+ * @param xUnitoCredentialId The credential ID to use for the request
67
+ * @param path The path to the item to fetch
68
+ * @param headers The headers to include in the request
69
+ * @param opts Additional options
70
+ * @returns A successful response containing an Item, or an ErrorResponse
71
+ */
72
+ export async function getProxyGraphItem(xUnitoCredentialId, path, { xUnitoCorrelationId, xUnitoAdditionalLoggingContext, } = {}, opts) {
73
+ const response = await getProxyGraph(xUnitoCredentialId, path, {
74
+ xUnitoCorrelationId,
75
+ xUnitoAdditionalLoggingContext,
76
+ }, opts);
77
+ if (isItemResponse(response) || isErrorResponse(response)) {
78
+ return response;
79
+ }
80
+ else {
81
+ throw new Error(`Response does not match expected Item shape`);
82
+ }
83
+ }
84
+ /**
85
+ * Wrapper of getProxyGraph that returns a typed response containing a Collection upon success.
86
+ *
87
+ * @param xUnitoCredentialId The credential ID to use for the request
88
+ * @param path The path to the item to fetch
89
+ * @param headers The headers to include in the request
90
+ * @param opts Additional options
91
+ * @returns A successful response containing an Collection, or an ErrorResponse
92
+ */
93
+ export async function getProxyGraphCollection(xUnitoCredentialId, path, { xUnitoCorrelationId, xUnitoAdditionalLoggingContext, } = {}, opts) {
94
+ const response = await getProxyGraph(xUnitoCredentialId, path, {
95
+ xUnitoCorrelationId,
96
+ xUnitoAdditionalLoggingContext,
97
+ }, opts);
98
+ if (isCollectionResponse(response) || isErrorResponse(response)) {
99
+ return response;
100
+ }
101
+ else {
102
+ throw new Error(`Response does not match expected Collection shape`);
103
+ }
104
+ }
105
+ /**
106
+ * Wrapper of patchProxyGraph that returns a typed response containing the updated Item upon success.
107
+ *
108
+ * @param xUnitoCredentialId The credential ID to use for the request
109
+ * @param path The path to the item to fetch
110
+ * @param headers The headers to include in the request
111
+ * @param opts Additional options
112
+ * @returns A successful response containing an Item, or an ErrorResponse
113
+ */
114
+ export async function patchProxyGraphItem(xUnitoCredentialId, path, body, { xUnitoCorrelationId, xUnitoAdditionalLoggingContext, } = {}, opts) {
115
+ const response = await patchProxyGraph(xUnitoCredentialId, path, body, {
116
+ xUnitoCorrelationId,
117
+ xUnitoAdditionalLoggingContext,
118
+ }, opts);
119
+ if (isItemResponse(response) || isErrorResponse(response)) {
120
+ return response;
121
+ }
122
+ else {
123
+ throw new Error(`Response does not match expected Item shape`);
124
+ }
125
+ }
126
+ /**
127
+ * Wrapper of postProxyGraph that returns a typed response containing the created ItemSummary upon success.
128
+ *
129
+ * @param xUnitoCredentialId The credential ID to use for the request
130
+ * @param path The path to the item to fetch
131
+ * @param headers The headers to include in the request
132
+ * @param opts Additional options
133
+ * @returns A successful response containing an ItemSummary, or an ErrorResponse
134
+ */
135
+ export async function postProxyGraphCollection(xUnitoCredentialId, path, body, { xUnitoCorrelationId, xUnitoAdditionalLoggingContext, } = {}, opts) {
136
+ const response = await postProxyGraph(xUnitoCredentialId, path, body, {
137
+ xUnitoCorrelationId,
138
+ xUnitoAdditionalLoggingContext,
139
+ }, opts);
140
+ if (isItemSummaryResponse(response) || isErrorResponse(response)) {
141
+ return response;
142
+ }
143
+ else {
144
+ throw new Error(`Response does not match expected ItemSummary shape`);
145
+ }
146
+ }
147
+ /**
148
+ * Wrapper of deleteProxyGraph added for uniformity, doesn't provide much typing help.
149
+ *
150
+ * @param xUnitoCredentialId The credential ID to use for the request
151
+ * @param path The path to the item to fetch
152
+ * @param headers The headers to include in the request
153
+ * @param opts Additional options
154
+ */
155
+ export async function deleteProxyGraphItem(xUnitoCredentialId, path, { xUnitoCorrelationId, xUnitoAdditionalLoggingContext, } = {}, opts) {
156
+ await deleteProxyGraph(xUnitoCredentialId, path, {
157
+ xUnitoCorrelationId,
158
+ xUnitoAdditionalLoggingContext,
159
+ }, opts);
160
+ }
161
+ /**
162
+ * Call an integration's graph and returns the fetch response directly to enable streaming of the body as it comes in.
163
+ *
164
+ * @param xUnitoCredentialId The credential ID to use for the request
165
+ * @param path The path to the item to fetch
166
+ * @param headers Base headers to add to the request
167
+ * @param additionalHeaders Additional headers to add to the request
168
+ * @returns fetch's response
169
+ */
170
+ export async function fetchProxyGraph(xUnitoCredentialId, path, { xUnitoCorrelationId, xUnitoAdditionalLoggingContext, accept, } = {}, init) {
171
+ return fetch(`${defaults.baseUrl}/proxy/graph${QS.query(QS.explode({ path }))}`, {
172
+ ...(init ?? {}),
173
+ headers: oazapfts.mergeHeaders({
174
+ ...defaults.headers,
175
+ ...(init?.headers ?? {}),
176
+ 'X-Unito-Credential-Id': xUnitoCredentialId,
177
+ 'X-Unito-Correlation-Id': xUnitoCorrelationId,
178
+ 'X-Unito-Additional-Logging-Context': xUnitoAdditionalLoggingContext,
179
+ Accept: accept,
180
+ }),
181
+ });
182
+ }