New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nuclia/sync-agent

Package Overview
Dependencies
Maintainers
3
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuclia/sync-agent - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

28

build/logic/sync/domain/sync.entity.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -8,2 +17,4 @@ exports.SyncEntity = exports.FiltersValidator = exports.NucliaOptionsValidator = void 0;

const factory_1 = require("../../connector/infrastructure/factory");
const core_1 = require("@nuclia/core");
const errors_1 = require("../../errors");
exports.NucliaOptionsValidator = zod_1.z.object({

@@ -117,3 +128,20 @@ /**

}
checkNucliaAuth(token) {
return __awaiter(this, void 0, void 0, function* () {
// If there is no zone, it is a local NucliaDB or a unit test, we do not check the auth
if (!this.kb.zone) {
return Promise.resolve(true);
}
try {
const nuclia = new core_1.Nuclia(Object.assign(Object.assign({}, this.kb), { apiKey: '' }));
nuclia.auth.authenticate({ access_token: token, refresh_token: '' });
const req = yield (0, rxjs_1.firstValueFrom)(nuclia.knowledgeBox.getConfiguration().pipe((0, rxjs_1.map)(() => true), (0, rxjs_1.catchError)(() => (0, rxjs_1.of)(false))));
return req;
}
catch (err) {
return new errors_1.CustomError('Error checking Nuclia auth', 500);
}
});
}
}
exports.SyncEntity = SyncEntity;

34

build/logic/sync/presentation/routes.js

@@ -28,2 +28,3 @@ "use strict";

const sync_repository_1 = require("../infrastructure/sync.repository");
const sync_entity_1 = require("../domain/sync.entity");
class SyncFileSystemRoutes {

@@ -52,6 +53,13 @@ constructor(basePath) {

}));
router.get('/', (_req, res) => __awaiter(this, void 0, void 0, function* () {
router.get('/kb/:kb', (_req, res) => __awaiter(this, void 0, void 0, function* () {
try {
const data = yield new get_all_sync_use_case_1.GetAllSync(syncRepository).execute();
res.status(200).send(data);
const allSyncs = yield new get_all_sync_use_case_1.GetAllSync(syncRepository).execute();
const kbSyncs = Object.values(allSyncs)
.filter((sync) => sync.kb.knowledgeBox === _req.params.kb)
.map((sync) => ({
id: sync.id,
title: sync.title,
connector: sync.connector.name,
}));
res.status(200).send(kbSyncs);
}

@@ -88,2 +96,3 @@ catch (error) {

try {
yield this.checkAuth(id, req.headers.token, syncRepository);
const data = yield new get_sync_use_case_1.GetSync(syncRepository).execute(id);

@@ -109,2 +118,3 @@ res.status(200).send(data);

try {
yield this.checkAuth(id, req.headers.token, syncRepository);
const data = yield new get_sync_folders_use_case_1.GetSyncFolders(syncRepository).execute(id);

@@ -123,2 +133,3 @@ res.status(200).send(data);

try {
yield this.checkAuth(id, req.headers.token, syncRepository);
yield new update_sync_use_case_1.UpdateSync(syncRepository).execute(updateSyncDto);

@@ -134,2 +145,3 @@ res.status(204).send(null);

try {
yield this.checkAuth(id, req.headers.token, syncRepository);
yield new delete_sync_use_case_1.DeleteSync(syncRepository).execute(id);

@@ -144,3 +156,19 @@ res.status(200).send(null);

}
checkAuth(id, auth, syncRepository) {
return __awaiter(this, void 0, void 0, function* () {
if (!auth) {
throw new errors_1.CustomError('Check auth: No auth token provided', 401);
}
const data = yield syncRepository.getSync(id);
if (data === null) {
throw new errors_1.CustomError(`Check auth: Sync with id ${id} not found`, 404);
}
const syncEntity = new sync_entity_1.SyncEntity(data);
const checkAuth = yield syncEntity.checkNucliaAuth(auth);
if (!checkAuth) {
throw new errors_1.CustomError(`Check auth: Auth for sync with id ${id} not valid`, 401);
}
});
}
}
exports.SyncFileSystemRoutes = SyncFileSystemRoutes;
import { Observable } from 'rxjs';
import { z } from 'zod';
import { IConnector, SearchResults, SyncItem } from '../../connector/domain/connector';
import { CustomError } from '../../errors';
export type Connector = {

@@ -122,2 +123,3 @@ name: 'gdrive' | 'folder';

hasAuthData(): boolean;
checkNucliaAuth(token: string): Promise<boolean | CustomError>;
}

@@ -7,2 +7,3 @@ import { Router } from 'express';

getRoutes(): Router;
private checkAuth;
}

2

package.json
{
"name": "@nuclia/sync-agent",
"version": "1.1.0",
"version": "1.2.0",
"description": "This is a sync agent to synchronize user files from diferent sources to nuclia",

@@ -5,0 +5,0 @@ "main": "build/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc