diff --git a/package-lock.json b/package-lock.json index 351065c..1d2a899 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7080,7 +7080,7 @@ }, "packages/cli": { "name": "@apillon/cli", - "version": "1.4.0", + "version": "1.5.0", "license": "MIT", "dependencies": { "@apillon/sdk": "*", @@ -7119,7 +7119,7 @@ }, "packages/sdk": { "name": "@apillon/sdk", - "version": "3.4.0", + "version": "3.5.0", "license": "MIT", "dependencies": { "@polkadot/util-crypto": "^12.6.2", diff --git a/packages/cli/package.json b/packages/cli/package.json index 87ffbe2..b720d6e 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,7 +1,7 @@ { "name": "@apillon/cli", "description": "▶◀ Apillon CLI tools ▶◀", - "version": "1.4.0", + "version": "1.5.0", "author": "Apillon", "license": "MIT", "main": "./dist/index.js", diff --git a/packages/cli/src/modules/cloud-functions/cloud-functions.service.ts b/packages/cli/src/modules/cloud-functions/cloud-functions.service.ts index f122005..df3752f 100644 --- a/packages/cli/src/modules/cloud-functions/cloud-functions.service.ts +++ b/packages/cli/src/modules/cloud-functions/cloud-functions.service.ts @@ -33,10 +33,9 @@ export async function createCloudFunction(optsWithGlobals: GlobalOptions) { name: optsWithGlobals.name, description: optsWithGlobals.description, }); - if (data) { - console.log(data.serialize()); - console.log('Cloud function created successfully!'); - } + + console.log(data.serialize()); + console.log('Cloud function created successfully!'); }); } diff --git a/packages/cli/src/modules/indexing/indexing.service.ts b/packages/cli/src/modules/indexing/indexing.service.ts index ae647d5..fc9b9ea 100644 --- a/packages/cli/src/modules/indexing/indexing.service.ts +++ b/packages/cli/src/modules/indexing/indexing.service.ts @@ -8,14 +8,12 @@ export async function deployIndexer( ) { await withErrorHandler(async () => { console.log(`Deploying indexer: ${path}`); - const res = await new Indexing(optsWithGlobals) + await new Indexing(optsWithGlobals) .indexer(optsWithGlobals.indexerUuid) .deployIndexer(path); - if (res) { - console.log( - `Indexer deployment successfully started! Check Apillon console for status.`, - ); - } + console.log( + `Indexer deployment successfully started! Check Apillon console for status.`, + ); }); } diff --git a/packages/sdk/package.json b/packages/sdk/package.json index df0fd69..f893a0d 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,7 +1,7 @@ { "name": "@apillon/sdk", "description": "▶◀ Apillon SDK for NodeJS ▶◀", - "version": "3.4.0", + "version": "3.5.0", "author": "Apillon", "license": "MIT", "main": "./dist/index.js", diff --git a/packages/sdk/src/docs-index.ts b/packages/sdk/src/docs-index.ts index 89e2c65..426a920 100644 --- a/packages/sdk/src/docs-index.ts +++ b/packages/sdk/src/docs-index.ts @@ -23,3 +23,8 @@ export * from './modules/social/social'; export * from './modules/social/social-hub'; export * from './modules/social/social-channel'; export * from './modules/project/project'; +export * from './modules/cloud-functions/cloud-functions'; +export * from './modules/cloud-functions/cloud-function'; +export * from './modules/cloud-functions/cloud-function-job'; +export * from './modules/indexing/indexing'; +export * from './modules/indexing/indexer'; diff --git a/packages/sdk/src/modules/indexing/indexer.ts b/packages/sdk/src/modules/indexing/indexer.ts index 5903242..958f455 100644 --- a/packages/sdk/src/modules/indexing/indexer.ts +++ b/packages/sdk/src/modules/indexing/indexer.ts @@ -1,5 +1,6 @@ +/* eslint-disable security/detect-non-literal-fs-filename */ import axios from 'axios'; -import fs from 'fs'; +import * as fs from 'fs'; import { ApillonModel } from '../../lib/apillon'; import { ApillonApi } from '../../lib/apillon-api'; import { ApillonLogger } from '../../lib/apillon-logger'; @@ -40,10 +41,12 @@ export class Indexer extends ApillonModel { public async deployIndexer(path: string): Promise { //Check directory and if squid.yaml exists in it if (!fs.existsSync(path)) { - return console.error('Invalid path'); + throw new Error('Error deploying indexer: Invalid path'); } if (!fs.existsSync(`${path}/squid.yaml`)) { - return console.error('squid.yaml not found in directory'); + throw new Error( + 'Error deploying indexer: squid.yaml not found in directory', + ); } //Create tar.gz file @@ -53,7 +56,7 @@ export class Indexer extends ApillonModel { ); if (numOfFiles === 0) { - return console.error('Source directory is empty'); + throw new Error('Error deploying indexer: Source directory is empty'); } ApillonLogger.log(`Compressed ${numOfFiles} files. Uploading to s3...`); diff --git a/packages/sdk/src/tests/indexing.test.ts b/packages/sdk/src/tests/indexing.test.ts index 0dd3746..c2c4a5e 100644 --- a/packages/sdk/src/tests/indexing.test.ts +++ b/packages/sdk/src/tests/indexing.test.ts @@ -2,8 +2,8 @@ import { Indexing } from '../modules/indexing/indexing'; import { getConfig, getIndexerUUID } from './helpers/helper'; describe('Indexing tests', () => { - let indexing: Indexing = undefined; - let indexer_uuid: string = undefined; + let indexing: Indexing; + let indexer_uuid: string; beforeAll(async () => { indexing = new Indexing(getConfig()); @@ -22,14 +22,14 @@ describe('Indexing tests', () => { }); test('Deploy a indexer with invalid path, should return error', async () => { - const logSpy = jest.spyOn(global.console, 'error'); - await indexing.indexer(indexer_uuid).deployIndexer('some invalid path'); - expect(logSpy).toHaveBeenCalled(); + await expect( + indexing.indexer(getIndexerUUID()).deployIndexer('some invalid path'), + ).rejects.toThrow('Path does not exist'); }); test('Deploy a indexer with valid path but invalid content, should return error', async () => { - const logSpy = jest.spyOn(global.console, 'error'); - await indexing.indexer(indexer_uuid).deployIndexer('D:\\Sqd'); - expect(logSpy).toHaveBeenCalled(); + await expect( + indexing.indexer(getIndexerUUID()).deployIndexer('D:\\Sqd'), + ).rejects.toThrow('squid.yaml not found in directory'); }); }); diff --git a/packages/sdk/src/util/indexer-utils.ts b/packages/sdk/src/util/indexer-utils.ts index 90ebec0..f4cfef3 100644 --- a/packages/sdk/src/util/indexer-utils.ts +++ b/packages/sdk/src/util/indexer-utils.ts @@ -1,8 +1,10 @@ +/* eslint-disable security/detect-non-literal-fs-filename */ import fs from 'node:fs'; import path from 'node:path'; import { globSync } from 'glob'; import ignore from 'ignore'; import targz from 'targz'; +import { ApillonLogger } from '../lib/apillon-logger'; export function createSquidIgnore(squidDir: string) { const ig = ignore().add( @@ -86,28 +88,27 @@ export function compressIndexerSourceCode( src: srcDir, dest: destDir, tar: { - ignore: (name) => { + ignore: (name: string) => { const relativePath = path.relative( path.resolve(srcDir), path.resolve(name), ); if (squidIgnore.ignores(relativePath)) { - console.log('ignoring ' + relativePath); + ApillonLogger.log(`ignoring ${relativePath}`); return true; - } else { - console.log('adding ' + relativePath); - filesCount++; - return false; } + ApillonLogger.log(`adding ${relativePath}`); + filesCount++; + return false; }, }, }, - function (err) { + (err) => { if (err) { - console.error(err); + ApillonLogger.log(err); reject( - `Compression failed. ${err.message ? 'Error: ' + err.message : ''}`, + `Compression failed. ${err.message ? `Error: ${err.message}` : ''}`, ); } else { resolve(filesCount);