UNPKG

@finos/legend-server-marketplace

Version:
157 lines 8.64 kB
/** * Copyright (c) 2020-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { AbstractServerClient, isNonEmptyString, } from '@finos/legend-shared'; import { OrderStatusCategory, } from './models/TerminalProductOrder.js'; import { FieldSearchType, } from './models/FieldSearch.js'; export class MarketplaceServerClient extends AbstractServerClient { subscriptionUrl; constructor(config) { super({ baseUrl: config.serverUrl, networkClientOptions: { // NOTE: with the way we setup this server, we allow any (*) origin for CORS // so here we have to explicit omit credentials // See https://fetch.spec.whatwg.org/#concept-request-credentials-mode credentials: 'omit', }, }); this.subscriptionUrl = config.subscriptionUrl; } // ------------------------------------------- Vendors ------------------------------------------- _vendors = () => `${this.baseUrl}/v1/vendors`; getVendors = () => this.get(this._vendors()); _products = () => `${this.baseUrl}/v1/workflow/products`; fetchProducts = async (params) => { const queryParams = { kerberos: params.kerberos, product_type: params.product_type, preferred_products: params.preferred_products, }; if (params.page_number !== undefined) { queryParams.page_number = params.page_number; } if (params.page_size !== undefined) { queryParams.page_size = params.page_size; } if (params.search !== undefined && params.search !== '') { queryParams.search = params.search; } return this.get(this._products(), undefined, undefined, queryParams); }; // ------------------------------------------- Search ------------------------------------------- _search = () => `${this.baseUrl}/v1/search`; _autosuggest = () => `${this.baseUrl}/v1/autosuggest`; dataProductSearch = async (query, lakehouseEnv, searchType = 'hybrid', searchFilters = [], pageSize = 12, pageNumber = 1, showAll = false) => { const filters = searchFilters.join('&search_filters='); const searchFilterParam = filters ? `&search_filters=${filters}` : ''; return this.get(`${this._search()}/dataProducts/${lakehouseEnv}?query=${query}&search_type=${searchType}${searchFilterParam}&page_size=${pageSize}&page_number=${pageNumber}&include_filter_metadata=true&show_all=${showAll}`); }; fieldSearch = async (lakehouseEnv, params, signal) => this.get(`${this._search()}/fields/${lakehouseEnv}/grouped`, signal ? { signal } : {}, undefined, { query: params.query, search_type: params.searchType ?? FieldSearchType.HYBRID, page_size: params.pageSize ?? 12, page_number: params.pageNumber ?? 1, ...(params.dataProductTypes?.length ? { data_product_types: params.dataProductTypes } : {}), }); getAutosuggestions = async (query, environment, limit = 5, signal) => this.get(`${this._autosuggest()}/dataProducts/${environment}`, signal ? { signal } : {}, undefined, { query, limit }); datasetSearch = async (lakehouseEnv, groupId, artifactId, versionId, path, query, options) => this.get(`${this._search()}/datasets/${lakehouseEnv}/legacy`, undefined, undefined, { group_id: groupId, artifact_id: artifactId, version_id: versionId, path, query, search_type: options?.searchType ?? 'hybrid', page_size: options?.pageSize ?? 20, page_number: options?.pageNumber ?? 1, }); legacyFieldSearch = async (lakehouseEnv, groupId, artifactId, versionId, path, options) => this.get(`${this._search()}/fields/${lakehouseEnv}/legacy`, undefined, undefined, { group_id: groupId, artifact_id: artifactId, version_id: versionId, path, search_type: options?.searchType ?? 'hybrid', page_size: options?.pageSize ?? 20, page_number: options?.pageNumber ?? 1, }); entitySearch = async (lakehouseEnv, query, options) => this.get(`${this._search()}/entities/${lakehouseEnv}`, undefined, undefined, { query, group_id: options?.groupId, artifact_id: options?.artifactId, version_id: options?.versionId, path: options?.path, data_product_id: options?.dataProductId, deployment_id: options?.deploymentId, search_type: options?.searchType ?? 'hybrid', page_size: options?.pageSize ?? 10, page_number: options?.pageNumber ?? 1, include_primitive_fields: options?.includePrimitiveFields ?? true, }); // ------------------------------------------- Trending ------------------------------------------- _analytics = () => `${this.baseUrl}/v1/analytics`; getTrendingDataProducts = async (lakehouseEnv) => this.get(`${this._analytics()}/top-products/${lakehouseEnv}`, undefined, undefined); // ------------------------------------------- Taxonomy ------------------------------------------- _taxonomyTree = () => `${this.baseUrl}/v1/taxonomy/tree`; getTaxonomyTree = async (lakehouseEnv, searchQuery, refresh = false) => { const queryParams = { refresh, }; if (searchQuery) { queryParams.search_query = searchQuery; } return this.get(`${this._taxonomyTree()}/${lakehouseEnv}`, undefined, undefined, queryParams); }; // ------------------------------------------- Subscriptions ----------------------------------------- _subscriptions = (user) => `${this.baseUrl}/v1/service/subscription/${user}`; getSubscriptions = async (user) => this.get(this._subscriptions(user)); cancelSubscriptions = async (cancellationRequest) => this.post(`${this.baseUrl}/v1/workflow/cancel/subscription`, cancellationRequest); // ------------------------------------------- Cart ------------------------------------------- _cart = (user) => `${this.baseUrl}/v1/cart/${user}`; getCart = async (user) => this.get(this._cart(user)); getCartSummary = async (user) => this.get(`${this._cart(user)}/summary`); clearCart = async (user) => this.delete(this._cart(user)); deleteCartItem = async (user, cartId, confirmDelete) => this.delete(`${this._cart(user)}/item/${cartId}`, {}, {}, undefined, confirmDelete ? { confirm_delete: true } : undefined); addToCart = async (user, cartItemData) => this.post(this._cart(user), cartItemData); searchVendorAddons = async (user, providerName, params, signal) => { const queryParams = {}; if (params?.page !== undefined) { queryParams.page = params.page; } if (params?.page_size !== undefined) { queryParams.page_size = params.page_size; } if (isNonEmptyString(params?.search)) { queryParams.search = params.search; } if (params?.sort_by_price !== undefined) { queryParams.sort_by_price = params.sort_by_price; } return this.get(`${this._cart(user)}/vendor-addons/${encodeURIComponent(providerName)}`, signal ? { signal } : {}, undefined, queryParams); }; submitOrder = async (user, orderData) => this.post(`${this.baseUrl}/v1/workflow/create/order`, orderData); // ------------------------------------------- Orders ------------------------------------------- _orders = () => `${this.baseUrl}/v1/workflow/fetch/orders`; fetchOrders = async (user, category = OrderStatusCategory.OPEN) => this.get(this._orders(), undefined, undefined, { kerberos: user, category, }); cancelOrder = async (cancelData) => this.post(`${this.baseUrl}/v1/workflow/cancel/order`, cancelData); // ------------------------------------------- Feedback ------------------------------------------- _feedback = () => `${this.baseUrl}/v1/feedback`; submitFeedback = async (feedbackData) => this.post(this._feedback(), feedbackData); } //# sourceMappingURL=MarketplaceServerClient.js.map