@trackunit/irisx-proxy 0.0.18 → 0.0.21
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 +20 -2
- package/index.esm.js +20 -2
- package/package.json +1 -1
- package/src/useDatabricksToken.d.ts +94 -3
- package/src/useIrisAppProxy.d.ts +2 -5
package/index.cjs.js
CHANGED
|
@@ -142,6 +142,9 @@ const useIrisAppProxy = (props) => {
|
|
|
142
142
|
const [proxyData, setProxyData] = react.useState(null);
|
|
143
143
|
const [mutate, { loading }] = client.useMutation(IrisAppProxyFetchDocument);
|
|
144
144
|
const createRequest = () => {
|
|
145
|
+
if (!requestOptions) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
145
148
|
const request = {
|
|
146
149
|
...requestOptions,
|
|
147
150
|
headers: [{ name: "Accept-Profile", value: "default" }, ...requestOptions.headers],
|
|
@@ -162,7 +165,18 @@ const useIrisAppProxy = (props) => {
|
|
|
162
165
|
var _a, _b;
|
|
163
166
|
try {
|
|
164
167
|
const proxyRequest = request !== null && request !== void 0 ? request : createRequest();
|
|
165
|
-
if (
|
|
168
|
+
if (proxyRequest === null) {
|
|
169
|
+
// Request can't be parsed
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (proxyRequest === undefined) {
|
|
173
|
+
// Request is not provided
|
|
174
|
+
const localError = {
|
|
175
|
+
name: `Error to create request`,
|
|
176
|
+
message: "The request doesn't follow IrisAppProxyRequestOptions schema or it's not provided.",
|
|
177
|
+
};
|
|
178
|
+
setError(localError);
|
|
179
|
+
onError && onError(localError);
|
|
166
180
|
return;
|
|
167
181
|
}
|
|
168
182
|
const { data, errors: gqlErrors } = await mutate({
|
|
@@ -334,8 +348,10 @@ const databricksTokenSchema = zod.z.object({
|
|
|
334
348
|
* Stored encoded value: `bXlDbGllbnRJZDpteUNsaWVudFNlY3JldA==`
|
|
335
349
|
* This key must be set up and stored in advance to successfully authenticate.
|
|
336
350
|
* @param {string[]} tableNames - An array of table names that the token will grant access to.
|
|
351
|
+
* @param onSuccess - A callback function that will be called when the token is successfully retrieved.
|
|
352
|
+
* @param onError - A callback function that will be called when an error occurs during the token retrieval process.
|
|
337
353
|
*/
|
|
338
|
-
const useDatabricksToken = ({ domainBase, encodedClientIdSecretVaultKey, tableNames, }) => {
|
|
354
|
+
const useDatabricksToken = ({ domainBase, encodedClientIdSecretVaultKey, tableNames, onSuccess, onError, }) => {
|
|
339
355
|
const encodedBody = react.useMemo(() => {
|
|
340
356
|
const authorization_details = JSON.stringify(tableNames.map(tableName => ({
|
|
341
357
|
type: "unity_catalog_permission",
|
|
@@ -360,6 +376,8 @@ const useDatabricksToken = ({ domainBase, encodedClientIdSecretVaultKey, tableNa
|
|
|
360
376
|
body: encodedBody,
|
|
361
377
|
},
|
|
362
378
|
responseSchema: databricksTokenSchema,
|
|
379
|
+
onSuccess,
|
|
380
|
+
onError,
|
|
363
381
|
});
|
|
364
382
|
return react.useMemo(() => ({
|
|
365
383
|
data: response.data,
|
package/index.esm.js
CHANGED
|
@@ -140,6 +140,9 @@ const useIrisAppProxy = (props) => {
|
|
|
140
140
|
const [proxyData, setProxyData] = useState(null);
|
|
141
141
|
const [mutate, { loading }] = useMutation(IrisAppProxyFetchDocument);
|
|
142
142
|
const createRequest = () => {
|
|
143
|
+
if (!requestOptions) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
143
146
|
const request = {
|
|
144
147
|
...requestOptions,
|
|
145
148
|
headers: [{ name: "Accept-Profile", value: "default" }, ...requestOptions.headers],
|
|
@@ -160,7 +163,18 @@ const useIrisAppProxy = (props) => {
|
|
|
160
163
|
var _a, _b;
|
|
161
164
|
try {
|
|
162
165
|
const proxyRequest = request !== null && request !== void 0 ? request : createRequest();
|
|
163
|
-
if (
|
|
166
|
+
if (proxyRequest === null) {
|
|
167
|
+
// Request can't be parsed
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (proxyRequest === undefined) {
|
|
171
|
+
// Request is not provided
|
|
172
|
+
const localError = {
|
|
173
|
+
name: `Error to create request`,
|
|
174
|
+
message: "The request doesn't follow IrisAppProxyRequestOptions schema or it's not provided.",
|
|
175
|
+
};
|
|
176
|
+
setError(localError);
|
|
177
|
+
onError && onError(localError);
|
|
164
178
|
return;
|
|
165
179
|
}
|
|
166
180
|
const { data, errors: gqlErrors } = await mutate({
|
|
@@ -332,8 +346,10 @@ const databricksTokenSchema = z.object({
|
|
|
332
346
|
* Stored encoded value: `bXlDbGllbnRJZDpteUNsaWVudFNlY3JldA==`
|
|
333
347
|
* This key must be set up and stored in advance to successfully authenticate.
|
|
334
348
|
* @param {string[]} tableNames - An array of table names that the token will grant access to.
|
|
349
|
+
* @param onSuccess - A callback function that will be called when the token is successfully retrieved.
|
|
350
|
+
* @param onError - A callback function that will be called when an error occurs during the token retrieval process.
|
|
335
351
|
*/
|
|
336
|
-
const useDatabricksToken = ({ domainBase, encodedClientIdSecretVaultKey, tableNames, }) => {
|
|
352
|
+
const useDatabricksToken = ({ domainBase, encodedClientIdSecretVaultKey, tableNames, onSuccess, onError, }) => {
|
|
337
353
|
const encodedBody = useMemo(() => {
|
|
338
354
|
const authorization_details = JSON.stringify(tableNames.map(tableName => ({
|
|
339
355
|
type: "unity_catalog_permission",
|
|
@@ -358,6 +374,8 @@ const useDatabricksToken = ({ domainBase, encodedClientIdSecretVaultKey, tableNa
|
|
|
358
374
|
body: encodedBody,
|
|
359
375
|
},
|
|
360
376
|
responseSchema: databricksTokenSchema,
|
|
377
|
+
onSuccess,
|
|
378
|
+
onError,
|
|
361
379
|
});
|
|
362
380
|
return useMemo(() => ({
|
|
363
381
|
data: response.data,
|
package/package.json
CHANGED
|
@@ -1,7 +1,96 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ProxyError } from "./useIrisAppProxy";
|
|
3
|
+
declare const databricksTokenSchema: z.ZodObject<{
|
|
4
|
+
access_token: z.ZodString;
|
|
5
|
+
authorization_details: z.ZodArray<z.ZodObject<{
|
|
6
|
+
securable_type: z.ZodString;
|
|
7
|
+
securable_object_name: z.ZodString;
|
|
8
|
+
operation: z.ZodString;
|
|
9
|
+
annotations: z.ZodObject<{
|
|
10
|
+
onlineViewName: z.ZodString;
|
|
11
|
+
onlineViewId: z.ZodString;
|
|
12
|
+
onlineViewMetastoreId: z.ZodString;
|
|
13
|
+
onlineViewClusterId: z.ZodString;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
onlineViewName: string;
|
|
16
|
+
onlineViewId: string;
|
|
17
|
+
onlineViewMetastoreId: string;
|
|
18
|
+
onlineViewClusterId: string;
|
|
19
|
+
}, {
|
|
20
|
+
onlineViewName: string;
|
|
21
|
+
onlineViewId: string;
|
|
22
|
+
onlineViewMetastoreId: string;
|
|
23
|
+
onlineViewClusterId: string;
|
|
24
|
+
}>;
|
|
25
|
+
type: z.ZodString;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
type: string;
|
|
28
|
+
securable_type: string;
|
|
29
|
+
securable_object_name: string;
|
|
30
|
+
operation: string;
|
|
31
|
+
annotations: {
|
|
32
|
+
onlineViewName: string;
|
|
33
|
+
onlineViewId: string;
|
|
34
|
+
onlineViewMetastoreId: string;
|
|
35
|
+
onlineViewClusterId: string;
|
|
36
|
+
};
|
|
37
|
+
}, {
|
|
38
|
+
type: string;
|
|
39
|
+
securable_type: string;
|
|
40
|
+
securable_object_name: string;
|
|
41
|
+
operation: string;
|
|
42
|
+
annotations: {
|
|
43
|
+
onlineViewName: string;
|
|
44
|
+
onlineViewId: string;
|
|
45
|
+
onlineViewMetastoreId: string;
|
|
46
|
+
onlineViewClusterId: string;
|
|
47
|
+
};
|
|
48
|
+
}>, "many">;
|
|
49
|
+
scope: z.ZodString;
|
|
50
|
+
token_type: z.ZodString;
|
|
51
|
+
expires_in: z.ZodNumber;
|
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
|
53
|
+
access_token: string;
|
|
54
|
+
authorization_details: {
|
|
55
|
+
type: string;
|
|
56
|
+
securable_type: string;
|
|
57
|
+
securable_object_name: string;
|
|
58
|
+
operation: string;
|
|
59
|
+
annotations: {
|
|
60
|
+
onlineViewName: string;
|
|
61
|
+
onlineViewId: string;
|
|
62
|
+
onlineViewMetastoreId: string;
|
|
63
|
+
onlineViewClusterId: string;
|
|
64
|
+
};
|
|
65
|
+
}[];
|
|
66
|
+
scope: string;
|
|
67
|
+
token_type: string;
|
|
68
|
+
expires_in: number;
|
|
69
|
+
}, {
|
|
70
|
+
access_token: string;
|
|
71
|
+
authorization_details: {
|
|
72
|
+
type: string;
|
|
73
|
+
securable_type: string;
|
|
74
|
+
securable_object_name: string;
|
|
75
|
+
operation: string;
|
|
76
|
+
annotations: {
|
|
77
|
+
onlineViewName: string;
|
|
78
|
+
onlineViewId: string;
|
|
79
|
+
onlineViewMetastoreId: string;
|
|
80
|
+
onlineViewClusterId: string;
|
|
81
|
+
};
|
|
82
|
+
}[];
|
|
83
|
+
scope: string;
|
|
84
|
+
token_type: string;
|
|
85
|
+
expires_in: number;
|
|
86
|
+
}>;
|
|
87
|
+
export type DatabricksTokenResponse = z.infer<typeof databricksTokenSchema>;
|
|
1
88
|
interface UseDatabricksTokenProps {
|
|
2
89
|
domainBase: string;
|
|
3
90
|
encodedClientIdSecretVaultKey: string;
|
|
4
91
|
tableNames: string[];
|
|
92
|
+
onSuccess?: (data: DatabricksTokenResponse) => void;
|
|
93
|
+
onError?: (error: ProxyError) => void;
|
|
5
94
|
}
|
|
6
95
|
/**
|
|
7
96
|
* Hook for retrieving an access token to interact with Databricks.
|
|
@@ -13,8 +102,10 @@ interface UseDatabricksTokenProps {
|
|
|
13
102
|
* Stored encoded value: `bXlDbGllbnRJZDpteUNsaWVudFNlY3JldA==`
|
|
14
103
|
* This key must be set up and stored in advance to successfully authenticate.
|
|
15
104
|
* @param {string[]} tableNames - An array of table names that the token will grant access to.
|
|
105
|
+
* @param onSuccess - A callback function that will be called when the token is successfully retrieved.
|
|
106
|
+
* @param onError - A callback function that will be called when an error occurs during the token retrieval process.
|
|
16
107
|
*/
|
|
17
|
-
export declare const useDatabricksToken: ({ domainBase, encodedClientIdSecretVaultKey, tableNames, }: UseDatabricksTokenProps) => {
|
|
108
|
+
export declare const useDatabricksToken: ({ domainBase, encodedClientIdSecretVaultKey, tableNames, onSuccess, onError, }: UseDatabricksTokenProps) => {
|
|
18
109
|
data: {
|
|
19
110
|
access_token: string;
|
|
20
111
|
authorization_details: {
|
|
@@ -34,7 +125,7 @@ export declare const useDatabricksToken: ({ domainBase, encodedClientIdSecretVau
|
|
|
34
125
|
expires_in: number;
|
|
35
126
|
} | null;
|
|
36
127
|
loading: boolean;
|
|
37
|
-
error:
|
|
128
|
+
error: ProxyError | null;
|
|
38
129
|
mutate: (request?: import("./schema").IrisAppProxyRequestOptions) => Promise<{
|
|
39
130
|
data?: {
|
|
40
131
|
access_token: string;
|
|
@@ -54,7 +145,7 @@ export declare const useDatabricksToken: ({ domainBase, encodedClientIdSecretVau
|
|
|
54
145
|
token_type: string;
|
|
55
146
|
expires_in: number;
|
|
56
147
|
} | undefined;
|
|
57
|
-
error?:
|
|
148
|
+
error?: ProxyError;
|
|
58
149
|
} | undefined>;
|
|
59
150
|
};
|
|
60
151
|
export {};
|
package/src/useIrisAppProxy.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { IrisAppProxyRequestOptions } from "./schema";
|
|
3
3
|
export interface UseIrisAppProxyProps<TResponse> {
|
|
4
|
-
requestOptions: IrisAppProxyRequestOptions;
|
|
5
4
|
responseSchema: z.ZodType<TResponse>;
|
|
5
|
+
requestOptions?: IrisAppProxyRequestOptions;
|
|
6
6
|
onSuccess?: (data: TResponse) => void;
|
|
7
|
-
onError?: (error:
|
|
8
|
-
name: string;
|
|
9
|
-
message: string;
|
|
10
|
-
}) => void;
|
|
7
|
+
onError?: (error: ProxyError) => void;
|
|
11
8
|
}
|
|
12
9
|
export interface ProxyError {
|
|
13
10
|
name: string;
|