@trackunit/irisx-proxy 0.0.14 → 0.0.15
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 +60 -6
- package/index.esm.js +60 -7
- package/package.json +1 -1
- package/src/index.d.ts +2 -1
- package/src/useDatabricksToken.d.ts +35 -0
- package/src/{useProxy.d.ts → useIrisAppProxy.d.ts} +11 -10
- package/src/utils.d.ts +1 -9
package/index.cjs.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
|
+
var react = require('react');
|
|
4
5
|
var client = require('@apollo/client');
|
|
5
6
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
6
|
-
var react = require('react');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Schema for HTTP headers
|
|
@@ -144,11 +144,7 @@ const useIrisAppProxy = (props) => {
|
|
|
144
144
|
const createRequest = () => {
|
|
145
145
|
const request = {
|
|
146
146
|
...requestOptions,
|
|
147
|
-
headers: [
|
|
148
|
-
{ name: "Content-Type", value: "application/json" },
|
|
149
|
-
{ name: "Accept-Profile", value: "default" },
|
|
150
|
-
...requestOptions.headers,
|
|
151
|
-
],
|
|
147
|
+
headers: [{ name: "Accept-Profile", value: "default" }, ...requestOptions.headers],
|
|
152
148
|
};
|
|
153
149
|
const result = irisAppProxySchema.safeParse(request);
|
|
154
150
|
if (!result.success) {
|
|
@@ -310,6 +306,64 @@ const useIrisAppProxy = (props) => {
|
|
|
310
306
|
return { data: proxyData, mutate: customMutate, loading, error, irisXProxyFetch };
|
|
311
307
|
};
|
|
312
308
|
|
|
309
|
+
const databricksTokenSchema = zod.z.object({
|
|
310
|
+
access_token: zod.z.string(),
|
|
311
|
+
authorization_details: zod.z.array(zod.z.object({
|
|
312
|
+
securable_type: zod.z.string(),
|
|
313
|
+
securable_object_name: zod.z.string(),
|
|
314
|
+
operation: zod.z.string(),
|
|
315
|
+
annotations: zod.z.object({
|
|
316
|
+
onlineViewName: zod.z.string(),
|
|
317
|
+
onlineViewId: zod.z.string(),
|
|
318
|
+
onlineViewMetastoreId: zod.z.string(),
|
|
319
|
+
onlineViewClusterId: zod.z.string(),
|
|
320
|
+
}),
|
|
321
|
+
type: zod.z.string(),
|
|
322
|
+
})),
|
|
323
|
+
scope: zod.z.string(),
|
|
324
|
+
token_type: zod.z.string(),
|
|
325
|
+
expires_in: zod.z.number(),
|
|
326
|
+
});
|
|
327
|
+
/**
|
|
328
|
+
* Hook for retrieving an access token to interact with Databricks.
|
|
329
|
+
* This hook fetches an authentication token needed to access specific tables within a Databricks workspace.
|
|
330
|
+
*
|
|
331
|
+
* @param {string} domainBase - The base domain URL of the Databricks workspace (e.g., 'mycompany.cloud.databricks.com').
|
|
332
|
+
* @param {string} encodedClientIdSecretVaultKey - A vault key pointing to a stored encoded base64 value in this format <clientId>:<clientSecret>.
|
|
333
|
+
* Example original value: `myClientId:myClientSecret`
|
|
334
|
+
* Stored encoded value: `bXlDbGllbnRJZDpteUNsaWVudFNlY3JldA==`
|
|
335
|
+
* This key must be set up and stored in advance to successfully authenticate.
|
|
336
|
+
* @param {string[]} tableNames - An array of table names that the token will grant access to.
|
|
337
|
+
*/
|
|
338
|
+
const useDatabricksToken = ({ domainBase, encodedClientIdSecretVaultKey, tableNames, }) => {
|
|
339
|
+
const encodedBody = react.useMemo(() => {
|
|
340
|
+
const authorization_details = JSON.stringify(tableNames.map(tableName => ({
|
|
341
|
+
type: "unity_catalog_permission",
|
|
342
|
+
securable_type: "table",
|
|
343
|
+
securable_object_name: tableName,
|
|
344
|
+
operation: "ReadOnlineView",
|
|
345
|
+
})));
|
|
346
|
+
const data = new URLSearchParams();
|
|
347
|
+
data.append("grant_type", "client_credentials");
|
|
348
|
+
data.append("scope", "all-apis");
|
|
349
|
+
data.append("authorization_details", authorization_details);
|
|
350
|
+
return btoa(data.toString());
|
|
351
|
+
}, [tableNames]);
|
|
352
|
+
return useIrisAppProxy({
|
|
353
|
+
requestOptions: {
|
|
354
|
+
url: `https://${domainBase}.cloud.databricks.com/oidc/v1/token`,
|
|
355
|
+
method: "POST",
|
|
356
|
+
headers: [
|
|
357
|
+
{ name: "Authorization", value: `Basic {{${encodedClientIdSecretVaultKey}}}` },
|
|
358
|
+
{ name: "Content-Type", value: "application/x-www-form-urlencoded" },
|
|
359
|
+
],
|
|
360
|
+
body: encodedBody,
|
|
361
|
+
},
|
|
362
|
+
responseSchema: databricksTokenSchema,
|
|
363
|
+
});
|
|
364
|
+
};
|
|
365
|
+
|
|
313
366
|
exports.headerSchema = headerSchema;
|
|
314
367
|
exports.irisAppProxySchema = irisAppProxySchema;
|
|
368
|
+
exports.useDatabricksToken = useDatabricksToken;
|
|
315
369
|
exports.useIrisAppProxy = useIrisAppProxy;
|
package/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { useState, useMemo } from 'react';
|
|
2
3
|
import { useMutation } from '@apollo/client';
|
|
3
4
|
import { objectEntries } from '@trackunit/shared-utils';
|
|
4
|
-
import { useState } from 'react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Schema for HTTP headers
|
|
@@ -142,11 +142,7 @@ const useIrisAppProxy = (props) => {
|
|
|
142
142
|
const createRequest = () => {
|
|
143
143
|
const request = {
|
|
144
144
|
...requestOptions,
|
|
145
|
-
headers: [
|
|
146
|
-
{ name: "Content-Type", value: "application/json" },
|
|
147
|
-
{ name: "Accept-Profile", value: "default" },
|
|
148
|
-
...requestOptions.headers,
|
|
149
|
-
],
|
|
145
|
+
headers: [{ name: "Accept-Profile", value: "default" }, ...requestOptions.headers],
|
|
150
146
|
};
|
|
151
147
|
const result = irisAppProxySchema.safeParse(request);
|
|
152
148
|
if (!result.success) {
|
|
@@ -308,4 +304,61 @@ const useIrisAppProxy = (props) => {
|
|
|
308
304
|
return { data: proxyData, mutate: customMutate, loading, error, irisXProxyFetch };
|
|
309
305
|
};
|
|
310
306
|
|
|
311
|
-
|
|
307
|
+
const databricksTokenSchema = z.object({
|
|
308
|
+
access_token: z.string(),
|
|
309
|
+
authorization_details: z.array(z.object({
|
|
310
|
+
securable_type: z.string(),
|
|
311
|
+
securable_object_name: z.string(),
|
|
312
|
+
operation: z.string(),
|
|
313
|
+
annotations: z.object({
|
|
314
|
+
onlineViewName: z.string(),
|
|
315
|
+
onlineViewId: z.string(),
|
|
316
|
+
onlineViewMetastoreId: z.string(),
|
|
317
|
+
onlineViewClusterId: z.string(),
|
|
318
|
+
}),
|
|
319
|
+
type: z.string(),
|
|
320
|
+
})),
|
|
321
|
+
scope: z.string(),
|
|
322
|
+
token_type: z.string(),
|
|
323
|
+
expires_in: z.number(),
|
|
324
|
+
});
|
|
325
|
+
/**
|
|
326
|
+
* Hook for retrieving an access token to interact with Databricks.
|
|
327
|
+
* This hook fetches an authentication token needed to access specific tables within a Databricks workspace.
|
|
328
|
+
*
|
|
329
|
+
* @param {string} domainBase - The base domain URL of the Databricks workspace (e.g., 'mycompany.cloud.databricks.com').
|
|
330
|
+
* @param {string} encodedClientIdSecretVaultKey - A vault key pointing to a stored encoded base64 value in this format <clientId>:<clientSecret>.
|
|
331
|
+
* Example original value: `myClientId:myClientSecret`
|
|
332
|
+
* Stored encoded value: `bXlDbGllbnRJZDpteUNsaWVudFNlY3JldA==`
|
|
333
|
+
* This key must be set up and stored in advance to successfully authenticate.
|
|
334
|
+
* @param {string[]} tableNames - An array of table names that the token will grant access to.
|
|
335
|
+
*/
|
|
336
|
+
const useDatabricksToken = ({ domainBase, encodedClientIdSecretVaultKey, tableNames, }) => {
|
|
337
|
+
const encodedBody = useMemo(() => {
|
|
338
|
+
const authorization_details = JSON.stringify(tableNames.map(tableName => ({
|
|
339
|
+
type: "unity_catalog_permission",
|
|
340
|
+
securable_type: "table",
|
|
341
|
+
securable_object_name: tableName,
|
|
342
|
+
operation: "ReadOnlineView",
|
|
343
|
+
})));
|
|
344
|
+
const data = new URLSearchParams();
|
|
345
|
+
data.append("grant_type", "client_credentials");
|
|
346
|
+
data.append("scope", "all-apis");
|
|
347
|
+
data.append("authorization_details", authorization_details);
|
|
348
|
+
return btoa(data.toString());
|
|
349
|
+
}, [tableNames]);
|
|
350
|
+
return useIrisAppProxy({
|
|
351
|
+
requestOptions: {
|
|
352
|
+
url: `https://${domainBase}.cloud.databricks.com/oidc/v1/token`,
|
|
353
|
+
method: "POST",
|
|
354
|
+
headers: [
|
|
355
|
+
{ name: "Authorization", value: `Basic {{${encodedClientIdSecretVaultKey}}}` },
|
|
356
|
+
{ name: "Content-Type", value: "application/x-www-form-urlencoded" },
|
|
357
|
+
],
|
|
358
|
+
body: encodedBody,
|
|
359
|
+
},
|
|
360
|
+
responseSchema: databricksTokenSchema,
|
|
361
|
+
});
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
export { headerSchema, irisAppProxySchema, useDatabricksToken, useIrisAppProxy };
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
interface UseDatabricksTokenProps {
|
|
2
|
+
domainBase: string;
|
|
3
|
+
encodedClientIdSecretVaultKey: string;
|
|
4
|
+
tableNames: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Hook for retrieving an access token to interact with Databricks.
|
|
8
|
+
* This hook fetches an authentication token needed to access specific tables within a Databricks workspace.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} domainBase - The base domain URL of the Databricks workspace (e.g., 'mycompany.cloud.databricks.com').
|
|
11
|
+
* @param {string} encodedClientIdSecretVaultKey - A vault key pointing to a stored encoded base64 value in this format <clientId>:<clientSecret>.
|
|
12
|
+
* Example original value: `myClientId:myClientSecret`
|
|
13
|
+
* Stored encoded value: `bXlDbGllbnRJZDpteUNsaWVudFNlY3JldA==`
|
|
14
|
+
* This key must be set up and stored in advance to successfully authenticate.
|
|
15
|
+
* @param {string[]} tableNames - An array of table names that the token will grant access to.
|
|
16
|
+
*/
|
|
17
|
+
export declare const useDatabricksToken: ({ domainBase, encodedClientIdSecretVaultKey, tableNames, }: UseDatabricksTokenProps) => import("./useIrisAppProxy").UseIrisAppProxyReturn<{
|
|
18
|
+
access_token: string;
|
|
19
|
+
authorization_details: {
|
|
20
|
+
type: string;
|
|
21
|
+
securable_type: string;
|
|
22
|
+
securable_object_name: string;
|
|
23
|
+
operation: string;
|
|
24
|
+
annotations: {
|
|
25
|
+
onlineViewName: string;
|
|
26
|
+
onlineViewId: string;
|
|
27
|
+
onlineViewMetastoreId: string;
|
|
28
|
+
onlineViewClusterId: string;
|
|
29
|
+
};
|
|
30
|
+
}[];
|
|
31
|
+
scope: string;
|
|
32
|
+
token_type: string;
|
|
33
|
+
expires_in: number;
|
|
34
|
+
}>;
|
|
35
|
+
export {};
|
|
@@ -13,19 +13,20 @@ export interface ProxyError {
|
|
|
13
13
|
name: string;
|
|
14
14
|
message: string;
|
|
15
15
|
}
|
|
16
|
+
export interface UseIrisAppProxyReturn<TResponse> {
|
|
17
|
+
data: TResponse | null;
|
|
18
|
+
error: ProxyError | null;
|
|
19
|
+
loading: boolean;
|
|
20
|
+
mutate: (request?: IrisAppProxyRequestOptions) => Promise<undefined | {
|
|
21
|
+
data?: TResponse;
|
|
22
|
+
error?: ProxyError;
|
|
23
|
+
}>;
|
|
24
|
+
irisXProxyFetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response | undefined>;
|
|
25
|
+
}
|
|
16
26
|
/**
|
|
17
27
|
* Hook for managing proxy interactions.
|
|
18
28
|
* This hook handles different layers of errors and responses from the provided endpoint through the IrisAppProxy.
|
|
19
29
|
* For the auth token, we recommend saving it using the IrisAppProxyStoreSecrets mutation and including it in the requestOptions as one of the headers.
|
|
20
30
|
* E.g. { name: "Authorization", value: `Bearer {{OAuthToken}}` }
|
|
21
31
|
*/
|
|
22
|
-
export declare const useIrisAppProxy: <TResponse>(props: UseIrisAppProxyProps<TResponse>) =>
|
|
23
|
-
data: TResponse | null;
|
|
24
|
-
mutate: (request?: IrisAppProxyRequestOptions) => Promise<{
|
|
25
|
-
data?: TResponse | undefined;
|
|
26
|
-
error?: ProxyError;
|
|
27
|
-
} | undefined>;
|
|
28
|
-
loading: boolean;
|
|
29
|
-
error: ProxyError | null;
|
|
30
|
-
irisXProxyFetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response | undefined>;
|
|
31
|
-
};
|
|
32
|
+
export declare const useIrisAppProxy: <TResponse>(props: UseIrisAppProxyProps<TResponse>) => UseIrisAppProxyReturn<TResponse>;
|
package/src/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { ProxyError } from "./
|
|
2
|
+
import { ProxyError } from "./useIrisAppProxy";
|
|
3
3
|
/**
|
|
4
4
|
* Validates and parses the response body.
|
|
5
5
|
*
|
|
@@ -12,11 +12,3 @@ export declare const validateAndParseResponse: <TResponse>(responseBody: string,
|
|
|
12
12
|
data?: TResponse;
|
|
13
13
|
error?: ProxyError;
|
|
14
14
|
};
|
|
15
|
-
/**
|
|
16
|
-
* Encodes the given request body as a base64 string.
|
|
17
|
-
*
|
|
18
|
-
* @template TRequest - The type of the request body.
|
|
19
|
-
* @param {TRequest} body - The request body to be encoded.
|
|
20
|
-
* @returns {string} The base64-encoded string representation of the request body.
|
|
21
|
-
*/
|
|
22
|
-
export declare const parseRequestBodyToBase64: <TRequest>(body: TRequest) => string;
|