// Copyright Abridged, Inc. 2021,2024. All Rights Reserved. // Node module: @collabland/sdk // This file is licensed under the MIT License. // License text available at https://opensource.org/license/mit/ import {inject} from '@loopback/core'; import fetch from 'cross-fetch'; import {initialize} from '../connectors/openapi.connector.js'; import {AnyObject} from '../types.js'; const config = { name: 'rest', url: undefined as string | undefined, positional: true, transformResponse: true, userFetch: fetch, }; export class RestDataSource { static dataSourceName = 'rest'; static readonly defaultConfig = config; private serviceProxies: AnyObject; constructor( @inject('datasources.config.rest', {optional: true}) readonly settings: AnyObject = config, ) {} async getService() { if (this.serviceProxies == null) { this.serviceProxies = await initialize(this); } return this.serviceProxies; } } export function getService(ds: RestDataSource) { return ds.getService() as Promise; }