@trackunit/irisx-proxy 0.0.31 → 0.0.33

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
@@ -1,35 +1,19 @@
1
1
  'use strict';
2
2
 
3
+ var utilities = require('@apollo/client/utilities');
4
+ var reactCoreContextsTest = require('@trackunit/react-core-contexts-test');
3
5
  var zod = require('zod');
4
6
  var react = require('react');
5
7
  var client = require('@apollo/client');
6
8
  var sharedUtils = require('@trackunit/shared-utils');
7
9
 
8
- /**
9
- * Schema for HTTP headers
10
- *
11
- * @property {string} name - The name of the header
12
- * @property {string} value - The value of the header
13
- */
14
- const headerSchema = zod.z.object({
15
- name: zod.z.string(),
16
- value: zod.z.string(),
17
- });
18
- /**
19
- * Schema for API call parameters
20
- *
21
- * @property {string} url - The URL for the API call (must be a valid URL)
22
- * @property {('GET'|'POST'|'PUT'|'PATCH'|'DELETE')} method - The HTTP method for the API call
23
- * @property {HeaderSchema[]} headers - An array of headers for the API call
24
- * @property {string} [body] - Optional body content for the API call
25
- */
26
- const irisAppProxySchema = zod.z.object({
27
- url: zod.z.string().url(),
28
- method: zod.z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]),
29
- headers: zod.z.array(headerSchema),
30
- body: zod.z.string().optional(),
31
- });
32
-
10
+ const httpMethod = {
11
+ DELETE: "DELETE",
12
+ GET: "GET",
13
+ PATCH: "PATCH",
14
+ POST: "POST",
15
+ PUT: "PUT",
16
+ };
33
17
  const IrisAppProxyFetchDocument = {
34
18
  kind: "Document",
35
19
  definitions: [
@@ -112,6 +96,44 @@ const IrisAppProxyFetchDocument = {
112
96
  ],
113
97
  };
114
98
 
99
+ const mockForIrisAppProxyFetchMutation = (variables, data) => {
100
+ return reactCoreContextsTest.queryFor(IrisAppProxyFetchDocument, variables, utilities.mergeDeep({
101
+ __typename: "Mutation",
102
+ irisAppProxyFetch: {
103
+ __typename: "IrisAppProxyFetchResponse",
104
+ success: false,
105
+ body: "subito",
106
+ status: 6273236744536064,
107
+ errorMessage: "subito",
108
+ },
109
+ }, data || {}));
110
+ };
111
+
112
+ /**
113
+ * Schema for HTTP headers
114
+ *
115
+ * @property {string} name - The name of the header
116
+ * @property {string} value - The value of the header
117
+ */
118
+ const headerSchema = zod.z.object({
119
+ name: zod.z.string(),
120
+ value: zod.z.string(),
121
+ });
122
+ /**
123
+ * Schema for API call parameters
124
+ *
125
+ * @property {string} url - The URL for the API call (must be a valid URL)
126
+ * @property {('GET'|'POST'|'PUT'|'PATCH'|'DELETE')} method - The HTTP method for the API call
127
+ * @property {HeaderSchema[]} headers - An array of headers for the API call
128
+ * @property {string} [body] - Optional body content for the API call
129
+ */
130
+ const irisAppProxySchema = zod.z.object({
131
+ url: zod.z.string().url(),
132
+ method: zod.z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]),
133
+ headers: zod.z.array(headerSchema),
134
+ body: zod.z.string().optional(),
135
+ });
136
+
115
137
  /**
116
138
  * Validates and parses the response body.
117
139
  *
@@ -141,7 +163,7 @@ const useIrisAppProxy = (props) => {
141
163
  const [error, setError] = react.useState(null);
142
164
  const [proxyData, setProxyData] = react.useState(null);
143
165
  const [mutate, { loading }] = client.useMutation(IrisAppProxyFetchDocument);
144
- const createRequest = () => {
166
+ const createRequest = react.useCallback(() => {
145
167
  if (!requestOptions) {
146
168
  return;
147
169
  }
@@ -160,8 +182,8 @@ const useIrisAppProxy = (props) => {
160
182
  return null;
161
183
  }
162
184
  return result.data;
163
- };
164
- const customMutate = async (request) => {
185
+ }, [onError, requestOptions]);
186
+ const customMutate = react.useCallback(async (request) => {
165
187
  var _a, _b;
166
188
  try {
167
189
  const proxyRequest = request !== null && request !== void 0 ? request : createRequest();
@@ -243,7 +265,7 @@ const useIrisAppProxy = (props) => {
243
265
  onError && onError(localError);
244
266
  return;
245
267
  }
246
- };
268
+ }, [createRequest, error, mutate, onError, onSuccess, responseSchema]);
247
269
  const convertHeadersToIrisAppProxySchema = (headers) => {
248
270
  if (!headers) {
249
271
  return [];
@@ -387,7 +409,10 @@ const useDatabricksToken = ({ domainBase, encodedClientIdSecretVaultKey, tableNa
387
409
  }), [response]);
388
410
  };
389
411
 
412
+ exports.IrisAppProxyFetchDocument = IrisAppProxyFetchDocument;
390
413
  exports.headerSchema = headerSchema;
414
+ exports.httpMethod = httpMethod;
391
415
  exports.irisAppProxySchema = irisAppProxySchema;
416
+ exports.mockForIrisAppProxyFetchMutation = mockForIrisAppProxyFetchMutation;
392
417
  exports.useDatabricksToken = useDatabricksToken;
393
418
  exports.useIrisAppProxy = useIrisAppProxy;
package/index.esm.js CHANGED
@@ -1,33 +1,17 @@
1
+ import { mergeDeep } from '@apollo/client/utilities';
2
+ import { queryFor } from '@trackunit/react-core-contexts-test';
1
3
  import { z } from 'zod';
2
- import { useState, useMemo } from 'react';
4
+ import { useState, useCallback, useMemo } from 'react';
3
5
  import { useMutation } from '@apollo/client';
4
6
  import { objectEntries } from '@trackunit/shared-utils';
5
7
 
6
- /**
7
- * Schema for HTTP headers
8
- *
9
- * @property {string} name - The name of the header
10
- * @property {string} value - The value of the header
11
- */
12
- const headerSchema = z.object({
13
- name: z.string(),
14
- value: z.string(),
15
- });
16
- /**
17
- * Schema for API call parameters
18
- *
19
- * @property {string} url - The URL for the API call (must be a valid URL)
20
- * @property {('GET'|'POST'|'PUT'|'PATCH'|'DELETE')} method - The HTTP method for the API call
21
- * @property {HeaderSchema[]} headers - An array of headers for the API call
22
- * @property {string} [body] - Optional body content for the API call
23
- */
24
- const irisAppProxySchema = z.object({
25
- url: z.string().url(),
26
- method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]),
27
- headers: z.array(headerSchema),
28
- body: z.string().optional(),
29
- });
30
-
8
+ const httpMethod = {
9
+ DELETE: "DELETE",
10
+ GET: "GET",
11
+ PATCH: "PATCH",
12
+ POST: "POST",
13
+ PUT: "PUT",
14
+ };
31
15
  const IrisAppProxyFetchDocument = {
32
16
  kind: "Document",
33
17
  definitions: [
@@ -110,6 +94,44 @@ const IrisAppProxyFetchDocument = {
110
94
  ],
111
95
  };
112
96
 
97
+ const mockForIrisAppProxyFetchMutation = (variables, data) => {
98
+ return queryFor(IrisAppProxyFetchDocument, variables, mergeDeep({
99
+ __typename: "Mutation",
100
+ irisAppProxyFetch: {
101
+ __typename: "IrisAppProxyFetchResponse",
102
+ success: false,
103
+ body: "subito",
104
+ status: 6273236744536064,
105
+ errorMessage: "subito",
106
+ },
107
+ }, data || {}));
108
+ };
109
+
110
+ /**
111
+ * Schema for HTTP headers
112
+ *
113
+ * @property {string} name - The name of the header
114
+ * @property {string} value - The value of the header
115
+ */
116
+ const headerSchema = z.object({
117
+ name: z.string(),
118
+ value: z.string(),
119
+ });
120
+ /**
121
+ * Schema for API call parameters
122
+ *
123
+ * @property {string} url - The URL for the API call (must be a valid URL)
124
+ * @property {('GET'|'POST'|'PUT'|'PATCH'|'DELETE')} method - The HTTP method for the API call
125
+ * @property {HeaderSchema[]} headers - An array of headers for the API call
126
+ * @property {string} [body] - Optional body content for the API call
127
+ */
128
+ const irisAppProxySchema = z.object({
129
+ url: z.string().url(),
130
+ method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]),
131
+ headers: z.array(headerSchema),
132
+ body: z.string().optional(),
133
+ });
134
+
113
135
  /**
114
136
  * Validates and parses the response body.
115
137
  *
@@ -139,7 +161,7 @@ const useIrisAppProxy = (props) => {
139
161
  const [error, setError] = useState(null);
140
162
  const [proxyData, setProxyData] = useState(null);
141
163
  const [mutate, { loading }] = useMutation(IrisAppProxyFetchDocument);
142
- const createRequest = () => {
164
+ const createRequest = useCallback(() => {
143
165
  if (!requestOptions) {
144
166
  return;
145
167
  }
@@ -158,8 +180,8 @@ const useIrisAppProxy = (props) => {
158
180
  return null;
159
181
  }
160
182
  return result.data;
161
- };
162
- const customMutate = async (request) => {
183
+ }, [onError, requestOptions]);
184
+ const customMutate = useCallback(async (request) => {
163
185
  var _a, _b;
164
186
  try {
165
187
  const proxyRequest = request !== null && request !== void 0 ? request : createRequest();
@@ -241,7 +263,7 @@ const useIrisAppProxy = (props) => {
241
263
  onError && onError(localError);
242
264
  return;
243
265
  }
244
- };
266
+ }, [createRequest, error, mutate, onError, onSuccess, responseSchema]);
245
267
  const convertHeadersToIrisAppProxySchema = (headers) => {
246
268
  if (!headers) {
247
269
  return [];
@@ -385,4 +407,4 @@ const useDatabricksToken = ({ domainBase, encodedClientIdSecretVaultKey, tableNa
385
407
  }), [response]);
386
408
  };
387
409
 
388
- export { headerSchema, irisAppProxySchema, useDatabricksToken, useIrisAppProxy };
410
+ export { IrisAppProxyFetchDocument, headerSchema, httpMethod, irisAppProxySchema, mockForIrisAppProxyFetchMutation, useDatabricksToken, useIrisAppProxy };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/irisx-proxy",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
package/src/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export * from "./generated/graphql-api/graphql";
2
+ export * from "./generated/graphql-api/mock";
1
3
  export * from "./schema";
2
4
  export * from "./useDatabricksToken";
3
5
  export * from "./useIrisAppProxy";