@gen3/core 0.11.62 → 0.12.1

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/dist/cjs/index.js CHANGED
@@ -51,8 +51,10 @@ const GUID_PREFIX_PATTERN = /^dg.[a-zA-Z0-9]+\//;
51
51
  const GEN3_MDS_API = process.env.NEXT_PUBLIC_GEN3_MDS_API || `${GEN3_API}/mds`;
52
52
  const GEN3_DOWNLOADS_ENDPOINT = process.env.NEXT_PUBLIC_GEN3_DOWNLOADS_ENDPOINT || 'downloads';
53
53
  const GEN3_FENCE_API = process.env.NEXT_PUBLIC_GEN3_FENCE_API || `${GEN3_API}/user`;
54
+ const GEN3_FENCE_SERVICE = process.env.GEN3_FENCE_SERVICE || 'http://fence-service';
54
55
  const GEN3_AI_SEARCH_API = process.env.NEXT_PUBLIC_GEN3_AI_SEARCH_API || `${GEN3_API}/ai-search`;
55
56
  const GEN3_AUTHZ_API = process.env.NEXT_PUBLIC_GEN3_AUTHZ_API || `${GEN3_API}/authz`;
57
+ const GEN3_AUTHZ_SERVICE = process.env.GEN3_AUTHZ_SERVICE || 'http://arborist-service';
56
58
  const GEN3_REDIRECT_URL = process.env.NEXT_PUBLIC_GEN3_REDIRECT_URL || GEN3_API;
57
59
  const GEN3_WORKSPACE_API = process.env.NEXT_PUBLIC_GEN3_WORKSPACE_STATUS_API || `${GEN3_API}/lw-workspace`;
58
60
  const GEN3_SUBMISSION_API = process.env.NEXT_PUBLIC_GEN3_SUBMISSION_API || `${GEN3_API}/api/v0/submission`;
@@ -79,47 +81,6 @@ const FILE_DELIMITERS = {
79
81
  };
80
82
  const CART_LIMIT = 80000;
81
83
 
82
- const isFetchError = (obj)=>{
83
- if (typeof obj !== 'object' || obj === null) {
84
- return false;
85
- }
86
- const { url, status, statusText, text } = obj;
87
- return typeof url === 'string' && typeof status === 'number' && typeof statusText === 'string' && typeof text === 'string';
88
- };
89
- /**
90
- * Template for fence error response dict
91
- * @returns: An error dict response from a RESTFUL API request
92
- */ const buildFetchError = async (res, request)=>{
93
- return {
94
- url: res.url,
95
- status: res.status,
96
- statusText: res.statusText,
97
- text: await res.text(),
98
- request: request
99
- };
100
- };
101
- /**
102
- * Template for a standard fence request
103
- * @returns: response data
104
- */ const fetchFence = async ({ endpoint, headers, body = {}, method = 'GET', isJSON = true })=>{
105
- const res = await fetch(`${GEN3_FENCE_API}${endpoint}`, {
106
- method: method,
107
- credentials: 'include',
108
- headers: headers,
109
- body: 'POST' === method ? JSON.stringify(body) : null
110
- });
111
- if (res.ok) return {
112
- data: isJSON ? await res.json() : await res.text(),
113
- status: res.status
114
- };
115
- throw await buildFetchError(res, {
116
- endpoint,
117
- method,
118
- headers,
119
- body
120
- });
121
- };
122
-
123
84
  const userAuthApi = react.createApi({
124
85
  reducerPath: 'userAuthApi',
125
86
  refetchOnMountOrArgChange: 1800,
@@ -268,6 +229,69 @@ const selectHeadersWithCSRFToken = toolkit.createSelector([
268
229
  const gen3ServicesReducer = gen3Api.reducer;
269
230
  const gen3ServicesReducerMiddleware = gen3Api.middleware;
270
231
 
232
+ const isFetchError = (obj)=>{
233
+ if (typeof obj !== 'object' || obj === null) {
234
+ return false;
235
+ }
236
+ const { url, status, statusText, text } = obj;
237
+ return typeof url === 'string' && typeof status === 'number' && typeof statusText === 'string' && typeof text === 'string';
238
+ };
239
+ /**
240
+ * Template for fence error response dict
241
+ * @returns: An error dict response from a RESTFUL API request
242
+ */ const buildFetchError = async (res, request)=>{
243
+ return {
244
+ url: res.url,
245
+ status: res.status,
246
+ statusText: res.statusText,
247
+ text: await res.text(),
248
+ request: request
249
+ };
250
+ };
251
+
252
+ /**
253
+ * Performs an asynchronous HTTP request to the Gen3 Fence API and processes the response.
254
+ *
255
+ * @template T The expected type of the response data.
256
+ * @param {FetchRequest} options The options for the fetch request.
257
+ * @param {string} options.endpoint The API endpoint to which the request will be sent.
258
+ * @param {Record<string, string>} options.headers An object representing the HTTP headers to include in the request.
259
+ * @param {Record<string, any>} [options.body={}] The request body to send with the fetch, used if the HTTP method is POST.
260
+ * @param {string} [options.method='GET'] The HTTP method for the request (e.g., 'GET', 'POST').
261
+ * @param {boolean} [options.isJSON=true] Determines if the response should be parsed as JSON or returned as plain text.
262
+ * @param useService { boolean } Uses fence_service instead of public fence API
263
+ * @returns {Promise<Gen3FenceResponse<T>>} A promise that resolves to the parsed data and response status
264
+ * or rejects with an error if the request fails.
265
+ * @throws {Error} Throws an error if the fetch request fails or the response is not successful.
266
+ */ const fetchFence = async ({ endpoint, headers, body = {}, method = 'GET', isJSON = true }, useService = false)=>{
267
+ let url = `${GEN3_FENCE_API}${endpoint}`;
268
+ if (useService) {
269
+ url = `${GEN3_FENCE_SERVICE}/${endpoint}`;
270
+ }
271
+ const res = await fetch(url, {
272
+ method: method,
273
+ credentials: 'include',
274
+ headers: {
275
+ // Ensure Content-Type is set for JSON POSTs, but allow overrides via 'headers'
276
+ ...method === 'POST' ? {
277
+ 'Content-Type': 'application/json'
278
+ } : {},
279
+ ...headers
280
+ },
281
+ body: 'POST' === method ? JSON.stringify(body) : null
282
+ });
283
+ if (res.ok) return {
284
+ data: isJSON ? await res.json() : await res.text(),
285
+ status: res.status
286
+ };
287
+ throw await buildFetchError(res, {
288
+ endpoint,
289
+ method,
290
+ headers,
291
+ body
292
+ });
293
+ };
294
+
271
295
  /**
272
296
  * Creates a fence API endpoint for handling login/data processes
273
297
  * @param endpoints - defined endpoint query for logging in
@@ -3742,7 +3766,6 @@ const authzTags = gen3Api.enhanceEndpoints({
3742
3766
  }),
3743
3767
  createAuthzResource: builder.mutation({
3744
3768
  query: (request)=>({
3745
- // url: `${GEN3_AUTHZ_API}/resources/${request.resourcePath}${request?.path ? `&p=${request.path}` : ''}`,
3746
3769
  url: `${GEN3_AUTHZ_API}/resources`,
3747
3770
  method: 'POST',
3748
3771
  body: request.data
@@ -3759,6 +3782,30 @@ const selectAuthzMappingData = toolkit.createSelector(selectAuthzMapping, (authz
3759
3782
  mappings: []
3760
3783
  });
3761
3784
 
3785
+ /**
3786
+ * Low-level helper to fetch Arborist resources for the current user.
3787
+ * Adds an Authorization header when a token is provided and normalizes the response
3788
+ * to a simple string[] of resource paths.
3789
+ *
3790
+ * token { string | null } - access token to use for authorization
3791
+ * useService { boolean } - use the arborist service endpoint instead of the public arborist API
3792
+ */ async function fetchArboristResources(token, useService = false) {
3793
+ const headers = {};
3794
+ if (token) {
3795
+ headers.Authorization = `Bearer ${token}`;
3796
+ }
3797
+ const url = useService ? `${GEN3_AUTHZ_SERVICE}/resource` : `${GEN3_AUTHZ_API}/resources`;
3798
+ const res = await fetch(url, {
3799
+ headers
3800
+ });
3801
+ if (!res.ok) {
3802
+ console.error('@gen3/core:fetchArboristResources /resource failed:', res.status, await res.text());
3803
+ return [];
3804
+ }
3805
+ const data = await res.json();
3806
+ return data.resources ?? [];
3807
+ }
3808
+
3762
3809
  class CohortStorage {
3763
3810
  constructor(config){
3764
3811
  this.databaseName = config.databaseName;
@@ -6267,11 +6314,13 @@ exports.FILE_DELIMITERS = FILE_DELIMITERS;
6267
6314
  exports.FILE_FORMATS = FILE_FORMATS;
6268
6315
  exports.GEN3_API = GEN3_API;
6269
6316
  exports.GEN3_AUTHZ_API = GEN3_AUTHZ_API;
6317
+ exports.GEN3_AUTHZ_SERVICE = GEN3_AUTHZ_SERVICE;
6270
6318
  exports.GEN3_COMMONS_NAME = GEN3_COMMONS_NAME;
6271
6319
  exports.GEN3_CROSSWALK_API = GEN3_CROSSWALK_API;
6272
6320
  exports.GEN3_DOMAIN = GEN3_DOMAIN;
6273
6321
  exports.GEN3_DOWNLOADS_ENDPOINT = GEN3_DOWNLOADS_ENDPOINT;
6274
6322
  exports.GEN3_FENCE_API = GEN3_FENCE_API;
6323
+ exports.GEN3_FENCE_SERVICE = GEN3_FENCE_SERVICE;
6275
6324
  exports.GEN3_GUPPY_API = GEN3_GUPPY_API;
6276
6325
  exports.GEN3_MANIFEST_API = GEN3_MANIFEST_API;
6277
6326
  exports.GEN3_MDS_API = GEN3_MDS_API;
@@ -6337,6 +6386,7 @@ exports.extractFiltersWithPrefixFromFilterSet = extractFiltersWithPrefixFromFilt
6337
6386
  exports.extractIndexAndFieldNameFromFullFieldName = extractIndexAndFieldNameFromFullFieldName;
6338
6387
  exports.extractIndexFromDataLibraryCohort = extractIndexFromDataLibraryCohort;
6339
6388
  exports.extractIndexFromFullFieldName = extractIndexFromFullFieldName;
6389
+ exports.fetchArboristResources = fetchArboristResources;
6340
6390
  exports.fetchFence = fetchFence;
6341
6391
  exports.fetchFencePresignedURL = fetchFencePresignedURL;
6342
6392
  exports.fetchJSONDataFromURL = fetchJSONDataFromURL;