@trackunit/irisx-proxy 1.0.6 → 1.0.8
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/index.cjs.js +9 -11
- package/index.esm.js +9 -11
- package/package.json +3 -3
package/index.cjs.js
CHANGED
|
@@ -184,9 +184,8 @@ const useIrisAppProxy = (props) => {
|
|
|
184
184
|
return result.data;
|
|
185
185
|
}, [onError, requestOptions]);
|
|
186
186
|
const customMutate = react.useCallback(async (request) => {
|
|
187
|
-
var _a, _b;
|
|
188
187
|
try {
|
|
189
|
-
const proxyRequest = request
|
|
188
|
+
const proxyRequest = request ?? createRequest();
|
|
190
189
|
if (proxyRequest === null) {
|
|
191
190
|
// Request can't be parsed
|
|
192
191
|
return;
|
|
@@ -218,7 +217,7 @@ const useIrisAppProxy = (props) => {
|
|
|
218
217
|
if (data && !data.irisAppProxyFetch.success) {
|
|
219
218
|
const localError = {
|
|
220
219
|
name: "Error from Proxy Fetch",
|
|
221
|
-
message: JSON.stringify(JSON.parse(
|
|
220
|
+
message: JSON.stringify(JSON.parse(data.irisAppProxyFetch.errorMessage ?? ""), null, 2),
|
|
222
221
|
};
|
|
223
222
|
setError(localError);
|
|
224
223
|
onError && onError(localError);
|
|
@@ -226,7 +225,7 @@ const useIrisAppProxy = (props) => {
|
|
|
226
225
|
}
|
|
227
226
|
// Handle errors from external service (These does not fail the GraphQL query)
|
|
228
227
|
if (data && data.irisAppProxyFetch.success && data.irisAppProxyFetch.status !== 200) {
|
|
229
|
-
const decodedBody = atob(
|
|
228
|
+
const decodedBody = atob(data.irisAppProxyFetch.body ?? "");
|
|
230
229
|
const localError = {
|
|
231
230
|
name: `Error from external service (${data.irisAppProxyFetch.status})`,
|
|
232
231
|
message: decodedBody,
|
|
@@ -236,7 +235,7 @@ const useIrisAppProxy = (props) => {
|
|
|
236
235
|
return;
|
|
237
236
|
}
|
|
238
237
|
// Handle successful response
|
|
239
|
-
if (data
|
|
238
|
+
if (data?.irisAppProxyFetch.body) {
|
|
240
239
|
const parsedBody = validateAndParseResponse(data.irisAppProxyFetch.body, responseSchema);
|
|
241
240
|
if (parsedBody.error) {
|
|
242
241
|
setError(parsedBody.error);
|
|
@@ -286,13 +285,12 @@ const useIrisAppProxy = (props) => {
|
|
|
286
285
|
return [];
|
|
287
286
|
};
|
|
288
287
|
const mapToIrisAppProxySchema = (input, init) => {
|
|
289
|
-
|
|
290
|
-
const headersArray = convertHeadersToIrisAppProxySchema(init === null || init === void 0 ? void 0 : init.headers);
|
|
288
|
+
const headersArray = convertHeadersToIrisAppProxySchema(init?.headers);
|
|
291
289
|
const result = irisAppProxySchema.safeParse({
|
|
292
290
|
url: input,
|
|
293
|
-
method:
|
|
291
|
+
method: init?.method ?? "GET",
|
|
294
292
|
headers: headersArray,
|
|
295
|
-
body:
|
|
293
|
+
body: init?.body ? String(init.body) : undefined,
|
|
296
294
|
});
|
|
297
295
|
if (!result.success) {
|
|
298
296
|
const localError = {
|
|
@@ -325,13 +323,13 @@ const useIrisAppProxy = (props) => {
|
|
|
325
323
|
return;
|
|
326
324
|
}
|
|
327
325
|
const response = await customMutate(proxyRequest);
|
|
328
|
-
if (response
|
|
326
|
+
if (response?.error) {
|
|
329
327
|
return new Response(JSON.stringify(response.error), {
|
|
330
328
|
status: 500,
|
|
331
329
|
headers: { "Content-Type": "application/json" },
|
|
332
330
|
});
|
|
333
331
|
}
|
|
334
|
-
if (response
|
|
332
|
+
if (response?.data) {
|
|
335
333
|
return new Response(JSON.stringify(response.data), {
|
|
336
334
|
status: 200,
|
|
337
335
|
headers: { "Content-Type": "application/json" },
|
package/index.esm.js
CHANGED
|
@@ -182,9 +182,8 @@ const useIrisAppProxy = (props) => {
|
|
|
182
182
|
return result.data;
|
|
183
183
|
}, [onError, requestOptions]);
|
|
184
184
|
const customMutate = useCallback(async (request) => {
|
|
185
|
-
var _a, _b;
|
|
186
185
|
try {
|
|
187
|
-
const proxyRequest = request
|
|
186
|
+
const proxyRequest = request ?? createRequest();
|
|
188
187
|
if (proxyRequest === null) {
|
|
189
188
|
// Request can't be parsed
|
|
190
189
|
return;
|
|
@@ -216,7 +215,7 @@ const useIrisAppProxy = (props) => {
|
|
|
216
215
|
if (data && !data.irisAppProxyFetch.success) {
|
|
217
216
|
const localError = {
|
|
218
217
|
name: "Error from Proxy Fetch",
|
|
219
|
-
message: JSON.stringify(JSON.parse(
|
|
218
|
+
message: JSON.stringify(JSON.parse(data.irisAppProxyFetch.errorMessage ?? ""), null, 2),
|
|
220
219
|
};
|
|
221
220
|
setError(localError);
|
|
222
221
|
onError && onError(localError);
|
|
@@ -224,7 +223,7 @@ const useIrisAppProxy = (props) => {
|
|
|
224
223
|
}
|
|
225
224
|
// Handle errors from external service (These does not fail the GraphQL query)
|
|
226
225
|
if (data && data.irisAppProxyFetch.success && data.irisAppProxyFetch.status !== 200) {
|
|
227
|
-
const decodedBody = atob(
|
|
226
|
+
const decodedBody = atob(data.irisAppProxyFetch.body ?? "");
|
|
228
227
|
const localError = {
|
|
229
228
|
name: `Error from external service (${data.irisAppProxyFetch.status})`,
|
|
230
229
|
message: decodedBody,
|
|
@@ -234,7 +233,7 @@ const useIrisAppProxy = (props) => {
|
|
|
234
233
|
return;
|
|
235
234
|
}
|
|
236
235
|
// Handle successful response
|
|
237
|
-
if (data
|
|
236
|
+
if (data?.irisAppProxyFetch.body) {
|
|
238
237
|
const parsedBody = validateAndParseResponse(data.irisAppProxyFetch.body, responseSchema);
|
|
239
238
|
if (parsedBody.error) {
|
|
240
239
|
setError(parsedBody.error);
|
|
@@ -284,13 +283,12 @@ const useIrisAppProxy = (props) => {
|
|
|
284
283
|
return [];
|
|
285
284
|
};
|
|
286
285
|
const mapToIrisAppProxySchema = (input, init) => {
|
|
287
|
-
|
|
288
|
-
const headersArray = convertHeadersToIrisAppProxySchema(init === null || init === void 0 ? void 0 : init.headers);
|
|
286
|
+
const headersArray = convertHeadersToIrisAppProxySchema(init?.headers);
|
|
289
287
|
const result = irisAppProxySchema.safeParse({
|
|
290
288
|
url: input,
|
|
291
|
-
method:
|
|
289
|
+
method: init?.method ?? "GET",
|
|
292
290
|
headers: headersArray,
|
|
293
|
-
body:
|
|
291
|
+
body: init?.body ? String(init.body) : undefined,
|
|
294
292
|
});
|
|
295
293
|
if (!result.success) {
|
|
296
294
|
const localError = {
|
|
@@ -323,13 +321,13 @@ const useIrisAppProxy = (props) => {
|
|
|
323
321
|
return;
|
|
324
322
|
}
|
|
325
323
|
const response = await customMutate(proxyRequest);
|
|
326
|
-
if (response
|
|
324
|
+
if (response?.error) {
|
|
327
325
|
return new Response(JSON.stringify(response.error), {
|
|
328
326
|
status: 500,
|
|
329
327
|
headers: { "Content-Type": "application/json" },
|
|
330
328
|
});
|
|
331
329
|
}
|
|
332
|
-
if (response
|
|
330
|
+
if (response?.data) {
|
|
333
331
|
return new Response(JSON.stringify(response.data), {
|
|
334
332
|
status: 200,
|
|
335
333
|
headers: { "Content-Type": "application/json" },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/irisx-proxy",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
15
15
|
"zod": "3.22.4",
|
|
16
16
|
"jest-fetch-mock": "^3.0.3",
|
|
17
|
-
"@trackunit/iris-app-build-utilities": "^1.0.
|
|
18
|
-
"@trackunit/iris-app-api": "^1.0.
|
|
17
|
+
"@trackunit/iris-app-build-utilities": "^1.0.5",
|
|
18
|
+
"@trackunit/iris-app-api": "^1.0.4",
|
|
19
19
|
"@trackunit/react-core-contexts-test": "^1.0.5",
|
|
20
20
|
"@trackunit/shared-utils": "^1.0.3"
|
|
21
21
|
},
|