/** * Copyright 2023 Kapeta Inc. * SPDX-License-Identifier: BUSL-1.1 */ import { BlockDefinition } from '@kapeta/schemas'; import * as yaml from 'js-yaml'; export class PredefinedBlock { constructor( public archetype: string, public kapetaYml: string, public gitRepo: { owner: string; repo: string; path: string; } ) {} public getGitRepo(): { owner: string; repo: string; path: string } { return this.gitRepo; } private async getKapetaYML(): Promise { const response = await fetch(this.kapetaYml); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } return await response.text(); } public async getBlockDefinition(): Promise { const kapetaYml = await this.getKapetaYML(); return yaml.load(kapetaYml) as BlockDefinition; } } const predefinedBlocks: PredefinedBlock[] = [ new PredefinedBlock( 'USER_SERVICE', 'https://raw.githubusercontent.com/kapetacom/everything/master/blocks/everything-user/kapeta.yml', { owner: 'kapetacom', repo: 'everything', path: 'blocks/everything-user', } ), ]; export const PREDEFINED_BLOCKS = new Map( predefinedBlocks.map((block) => [block.archetype, block]) );