@trackunit/irisx-proxy 0.0.4 → 0.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 CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var zod = require('zod');
4
4
  var client = require('@apollo/client');
5
+ var sharedUtils = require('@trackunit/shared-utils');
5
6
  var react = require('react');
6
7
 
7
8
  /**
@@ -114,10 +115,10 @@ const IrisAppProxyFetchDocument = {
114
115
  /**
115
116
  * Validates and parses the response body.
116
117
  *
117
- * @template T - The type inferred from the response schema.
118
+ * @template TResponse - The type inferred from the response schema.
118
119
  * @param {string} responseBody - The base64-encoded response body from the API.
119
- * @param {z.ZodType<T>} responseSchema - The Zod schema used to validate and parse the response data.
120
- * @returns {T | null} The parsed and validated response data of type `T`, or `null` if validation fails.
120
+ * @param {z.ZodType<TResponse>} responseSchema - The Zod schema used to validate and parse the response data.
121
+ * @returns {TResponse| null} The parsed and validated response data of type `T`, or `null` if validation fails.
121
122
  */
122
123
  const validateAndParseResponse = (responseBody, responseSchema) => {
123
124
  const decodedBody = atob(responseBody);
@@ -134,9 +135,6 @@ const validateAndParseResponse = (responseBody, responseSchema) => {
134
135
  * This hook handles different layers of errors and responses from the provided endpoint through the IrisAppProxy.
135
136
  * For the auth token, we recommend saving it using the IrisAppProxyStoreSecrets mutation and including it in the requestOptions as one of the headers.
136
137
  * E.g. { name: "Authorization", value: `Bearer {{OAuthToken}}` }
137
- *
138
- * @param props - The properties for useIrisAppProxy hook.
139
- * @returns An object containing chatbot state and functions.
140
138
  */
141
139
  const useIrisAppProxy = (props) => {
142
140
  const { requestOptions, responseSchema, onSuccess, onError } = props;
@@ -226,7 +224,7 @@ const useIrisAppProxy = (props) => {
226
224
  return;
227
225
  }
228
226
  }
229
- catch (error) {
227
+ catch (err) {
230
228
  const localError = {
231
229
  name: "Error",
232
230
  message: JSON.stringify(error, null, 2),
@@ -248,10 +246,10 @@ const useIrisAppProxy = (props) => {
248
246
  return headersArray;
249
247
  }
250
248
  if (Array.isArray(headers)) {
251
- return headers.map(([name, value]) => ({ name, value: value.toString() }));
249
+ return headers.map(([name, value]) => ({ name, value: value }));
252
250
  }
253
251
  if (typeof headers === "object") {
254
- return Object.entries(headers).map(([name, value]) => ({ name, value: value.toString() }));
252
+ return sharedUtils.objectEntries(headers).map(([name, value]) => ({ name, value: value }));
255
253
  }
256
254
  return [];
257
255
  };
package/index.esm.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { useMutation } from '@apollo/client';
3
+ import { objectEntries } from '@trackunit/shared-utils';
3
4
  import { useState } from 'react';
4
5
 
5
6
  /**
@@ -112,10 +113,10 @@ const IrisAppProxyFetchDocument = {
112
113
  /**
113
114
  * Validates and parses the response body.
114
115
  *
115
- * @template T - The type inferred from the response schema.
116
+ * @template TResponse - The type inferred from the response schema.
116
117
  * @param {string} responseBody - The base64-encoded response body from the API.
117
- * @param {z.ZodType<T>} responseSchema - The Zod schema used to validate and parse the response data.
118
- * @returns {T | null} The parsed and validated response data of type `T`, or `null` if validation fails.
118
+ * @param {z.ZodType<TResponse>} responseSchema - The Zod schema used to validate and parse the response data.
119
+ * @returns {TResponse| null} The parsed and validated response data of type `T`, or `null` if validation fails.
119
120
  */
120
121
  const validateAndParseResponse = (responseBody, responseSchema) => {
121
122
  const decodedBody = atob(responseBody);
@@ -132,9 +133,6 @@ const validateAndParseResponse = (responseBody, responseSchema) => {
132
133
  * This hook handles different layers of errors and responses from the provided endpoint through the IrisAppProxy.
133
134
  * For the auth token, we recommend saving it using the IrisAppProxyStoreSecrets mutation and including it in the requestOptions as one of the headers.
134
135
  * E.g. { name: "Authorization", value: `Bearer {{OAuthToken}}` }
135
- *
136
- * @param props - The properties for useIrisAppProxy hook.
137
- * @returns An object containing chatbot state and functions.
138
136
  */
139
137
  const useIrisAppProxy = (props) => {
140
138
  const { requestOptions, responseSchema, onSuccess, onError } = props;
@@ -224,7 +222,7 @@ const useIrisAppProxy = (props) => {
224
222
  return;
225
223
  }
226
224
  }
227
- catch (error) {
225
+ catch (err) {
228
226
  const localError = {
229
227
  name: "Error",
230
228
  message: JSON.stringify(error, null, 2),
@@ -246,10 +244,10 @@ const useIrisAppProxy = (props) => {
246
244
  return headersArray;
247
245
  }
248
246
  if (Array.isArray(headers)) {
249
- return headers.map(([name, value]) => ({ name, value: value.toString() }));
247
+ return headers.map(([name, value]) => ({ name, value: value }));
250
248
  }
251
249
  if (typeof headers === "object") {
252
- return Object.entries(headers).map(([name, value]) => ({ name, value: value.toString() }));
250
+ return objectEntries(headers).map(([name, value]) => ({ name, value: value }));
253
251
  }
254
252
  return [];
255
253
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/irisx-proxy",
3
- "version": "0.0.4",
3
+ "version": "0.0.8",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -16,7 +16,8 @@
16
16
  "@trackunit/iris-app-build-utilities": "*",
17
17
  "@trackunit/react-core-contexts-test": "*",
18
18
  "zod": "3.22.4",
19
- "jest-fetch-mock": "^3.0.3"
19
+ "jest-fetch-mock": "^3.0.3",
20
+ "@trackunit/shared-utils": "*"
20
21
  },
21
22
  "module": "./index.esm.js",
22
23
  "main": "./index.cjs.js",
package/src/useProxy.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { z } from "zod";
2
2
  import { IrisAppProxyRequestOptions } from "./schema";
3
- export interface UseIrisAppProxyProps<R> {
3
+ export interface UseIrisAppProxyProps<TResponse> {
4
4
  requestOptions: IrisAppProxyRequestOptions;
5
- responseSchema: z.ZodType<R>;
6
- onSuccess?: (data: R) => void;
5
+ responseSchema: z.ZodType<TResponse>;
6
+ onSuccess?: (data: TResponse) => void;
7
7
  onError?: (error: {
8
8
  name: string;
9
9
  message: string;
@@ -18,14 +18,11 @@ export interface ProxyError {
18
18
  * This hook handles different layers of errors and responses from the provided endpoint through the IrisAppProxy.
19
19
  * For the auth token, we recommend saving it using the IrisAppProxyStoreSecrets mutation and including it in the requestOptions as one of the headers.
20
20
  * E.g. { name: "Authorization", value: `Bearer {{OAuthToken}}` }
21
- *
22
- * @param props - The properties for useIrisAppProxy hook.
23
- * @returns An object containing chatbot state and functions.
24
21
  */
25
- export declare const useIrisAppProxy: <R>(props: UseIrisAppProxyProps<R>) => {
26
- data: R | null;
22
+ export declare const useIrisAppProxy: <TResponse>(props: UseIrisAppProxyProps<TResponse>) => {
23
+ data: TResponse | null;
27
24
  mutate: (request?: IrisAppProxyRequestOptions) => Promise<{
28
- data?: R | undefined;
25
+ data?: TResponse | undefined;
29
26
  error?: ProxyError;
30
27
  } | undefined>;
31
28
  loading: boolean;
package/src/utils.d.ts CHANGED
@@ -3,20 +3,20 @@ import { ProxyError } from "./useProxy";
3
3
  /**
4
4
  * Validates and parses the response body.
5
5
  *
6
- * @template T - The type inferred from the response schema.
6
+ * @template TResponse - The type inferred from the response schema.
7
7
  * @param {string} responseBody - The base64-encoded response body from the API.
8
- * @param {z.ZodType<T>} responseSchema - The Zod schema used to validate and parse the response data.
9
- * @returns {T | null} The parsed and validated response data of type `T`, or `null` if validation fails.
8
+ * @param {z.ZodType<TResponse>} responseSchema - The Zod schema used to validate and parse the response data.
9
+ * @returns {TResponse| null} The parsed and validated response data of type `T`, or `null` if validation fails.
10
10
  */
11
- export declare const validateAndParseResponse: <T>(responseBody: string, responseSchema: z.ZodType<T>) => {
12
- data?: T;
11
+ export declare const validateAndParseResponse: <TResponse>(responseBody: string, responseSchema: z.ZodType<TResponse>) => {
12
+ data?: TResponse;
13
13
  error?: ProxyError;
14
14
  };
15
15
  /**
16
16
  * Encodes the given request body as a base64 string.
17
17
  *
18
- * @template R - The type of the request body.
19
- * @param {R} body - The request body to be encoded.
18
+ * @template TRequest - The type of the request body.
19
+ * @param {TRequest} body - The request body to be encoded.
20
20
  * @returns {string} The base64-encoded string representation of the request body.
21
21
  */
22
- export declare const parseRequestBodyToBase64: <R>(body: R) => string;
22
+ export declare const parseRequestBodyToBase64: <TRequest>(body: TRequest) => string;