@nuclia/sync-agent
Advanced tools
Comparing version 1.2.15 to 1.2.16
@@ -109,3 +109,10 @@ "use strict"; | ||
}, | ||
}).then((res) => res.json(), (err) => { | ||
}).then((res) => { | ||
if (res.status === 401) { | ||
return { error: { status: 'UNAUTHENTICATED' } }; | ||
} | ||
else { | ||
return res.json(); | ||
} | ||
}, (err) => { | ||
console.error(`Error fetching about: ${err}`); | ||
@@ -254,3 +261,13 @@ throw new Error(err); | ||
} | ||
getGroups(resource) { | ||
return (0, rxjs_1.from)(fetch(`https://www.googleapis.com/drive/v3/files/${resource.originalId}?fields=permissions&corpora=allDrives&supportsAllDrives=true&includeItemsFromAllDrives=true`, { | ||
headers: { Authorization: `Bearer ${this.params.token}` }, | ||
})).pipe((0, rxjs_1.switchMap)((res) => res.json()), (0, rxjs_1.map)((res) => { | ||
const groups = (res.permissions || []) | ||
.filter((perm) => perm.type === 'group') | ||
.map((perm) => perm.emailAddress); | ||
return groups; | ||
})); | ||
} | ||
} | ||
exports.GDriveImpl = GDriveImpl; |
@@ -20,2 +20,3 @@ "use strict"; | ||
disabled: this.options.disabled, | ||
syncSecurityGroups: this.options.syncSecurityGroups, | ||
}; | ||
@@ -22,0 +23,0 @@ if (this.options.labels) |
@@ -32,2 +32,4 @@ "use strict"; | ||
returnObj.disabled = this.options.disabled; | ||
if (this.options.syncSecurityGroups !== undefined) | ||
returnObj.syncSecurityGroups = this.options.syncSecurityGroups; | ||
return returnObj; | ||
@@ -34,0 +36,0 @@ } |
@@ -26,5 +26,20 @@ "use strict"; | ||
upload(originalId, filename, data) { | ||
var _a, _b; | ||
const slug = sha256(originalId); | ||
const text = data.text; | ||
const buffer = data.buffer; | ||
const resourceData = { title: filename }; | ||
if (data.metadata.labels) { | ||
resourceData.usermetadata = { classifications: (_a = data.metadata) === null || _a === void 0 ? void 0 : _a.labels }; | ||
} | ||
if (data.metadata.path) { | ||
let path = data.metadata.path; | ||
if (path && !path.startsWith('/')) { | ||
path = `/${path}`; | ||
} | ||
resourceData.origin = { path }; | ||
} | ||
if ((_b = data.metadata) === null || _b === void 0 ? void 0 : _b.groups) { | ||
resourceData.security = { access_groups: data.metadata.groups }; | ||
} | ||
if (buffer || text) { | ||
@@ -34,5 +49,3 @@ return this.getKb().pipe((0, rxjs_1.switchMap)((kb) => kb.getResourceBySlug(slug, [], []).pipe((0, rxjs_1.switchMap)((resource) => { | ||
if ((_a = data.metadata) === null || _a === void 0 ? void 0 : _a.labels) { | ||
return resource | ||
.modify({ usermetadata: { classifications: data.metadata.labels } }) | ||
.pipe((0, rxjs_1.map)(() => resource)); | ||
return resource.modify(resourceData).pipe((0, rxjs_1.map)(() => resource)); | ||
} | ||
@@ -43,15 +56,4 @@ else { | ||
}), (0, rxjs_1.catchError)((error) => { | ||
var _a; | ||
if (error.status === 404) { | ||
const resourceData = { slug, title: filename }; | ||
if (data.metadata.labels) { | ||
resourceData.usermetadata = { classifications: (_a = data.metadata) === null || _a === void 0 ? void 0 : _a.labels }; | ||
} | ||
if (data.metadata.path) { | ||
let path = data.metadata.path; | ||
if (path && !path.startsWith('/')) { | ||
path = `/${path}`; | ||
} | ||
resourceData.origin = { path }; | ||
} | ||
resourceData.slug = slug; | ||
return kb.createResource(resourceData, true).pipe((0, rxjs_1.retry)(RETRY_CONFIG), (0, rxjs_1.map)((data) => kb.getResourceFromData({ id: data.uuid }))); | ||
@@ -58,0 +60,0 @@ } |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SyncEntity = exports.FiltersValidator = exports.NucliaOptionsValidator = exports.TO_BE_CHECKED = void 0; | ||
exports.SyncEntity = exports.ContentType = exports.FiltersValidator = exports.NucliaOptionsValidator = exports.TO_BE_CHECKED = void 0; | ||
const rxjs_1 = require("rxjs"); | ||
@@ -61,6 +61,12 @@ const zod_1 = require("zod"); | ||
}); | ||
var ContentType; | ||
(function (ContentType) { | ||
ContentType["blob"] = "blob"; | ||
ContentType["link"] = "link"; | ||
ContentType["text"] = "text"; | ||
})(ContentType || (exports.ContentType = ContentType = {})); | ||
class SyncEntity { | ||
constructor(options) { | ||
this.foldersToSync = []; | ||
const { connector, kb, labels, title, id, lastSyncGMT, foldersToSync, filters, disabled } = options; | ||
const { connector, kb, labels, title, id, lastSyncGMT, foldersToSync, filters, disabled, syncSecurityGroups } = options; | ||
this.connector = connector; | ||
@@ -75,2 +81,3 @@ this.kb = kb; | ||
this.disabled = disabled; | ||
this.syncSecurityGroups = syncSecurityGroups; | ||
this.setConnectorDefinition(); | ||
@@ -77,0 +84,0 @@ } |
@@ -12,9 +12,21 @@ "use strict"; | ||
const connector = sync.sourceConnector; | ||
if (connector === null || connector === void 0 ? void 0 : connector.isExternal) { | ||
return connector.getLink(item).pipe((0, rxjs_1.map)((link) => ({ type: 'link', link }))); | ||
if (!connector) { | ||
throw new Error('No connector found'); | ||
} | ||
else { | ||
return connector | ||
.download(item) | ||
.pipe((0, rxjs_1.map)((res) => (res instanceof Blob ? { type: 'blob', blob: res } : { type: 'text', text: res }))); | ||
if (connector === null || connector === void 0 ? void 0 : connector.isExternal) { | ||
return connector.getLink(item).pipe((0, rxjs_1.map)((link) => ({ type: sync_entity_1.ContentType.link, link }))); | ||
} | ||
else { | ||
return connector.download(item).pipe((0, rxjs_1.map)((res) => res instanceof Blob ? { type: sync_entity_1.ContentType.blob, blob: res } : { type: sync_entity_1.ContentType.text, text: res }), (0, rxjs_1.switchMap)((res) => { | ||
if (sync.syncSecurityGroups && connector.getGroups) { | ||
return connector.getGroups(item).pipe((0, rxjs_1.map)((groups) => { | ||
return Object.assign(Object.assign({}, res), { extra: { groups } }); | ||
})); | ||
} | ||
else { | ||
return (0, rxjs_1.of)(res); | ||
} | ||
})); | ||
} | ||
} | ||
@@ -36,8 +48,10 @@ } | ||
return downloadFileOrLink(sync, item).pipe((0, rxjs_1.switchMap)((data) => { | ||
var _a; | ||
try { | ||
if (data.type === 'blob' && data.blob) { | ||
if (data.type === sync_entity_1.ContentType.blob && data.blob) { | ||
return (0, rxjs_1.from)(data.blob.arrayBuffer()).pipe((0, rxjs_1.switchMap)((arrayBuffer) => { | ||
var _a; | ||
return nucliaConnector.upload(item.originalId, item.title, { | ||
buffer: arrayBuffer, | ||
metadata: Object.assign(Object.assign({}, item.metadata), { labels: sync.labels }), | ||
metadata: Object.assign(Object.assign({}, item.metadata), { labels: sync.labels, groups: (_a = data.extra) === null || _a === void 0 ? void 0 : _a.groups }), | ||
mimeType: item.mimeType, | ||
@@ -47,9 +61,9 @@ }); | ||
} | ||
else if (data.type === 'text' && data.text) { | ||
else if (data.type === sync_entity_1.ContentType.text && data.text) { | ||
return nucliaConnector.upload(item.originalId, item.title, { | ||
text: data.text, | ||
metadata: { labels: sync.labels }, | ||
metadata: { labels: sync.labels, groups: (_a = data.extra) === null || _a === void 0 ? void 0 : _a.groups }, | ||
}); | ||
} | ||
else if (data.type === 'link' && data.link) { | ||
else if (data.type === sync_entity_1.ContentType.link && data.link) { | ||
const mimeType = item.mimeType !== sync_entity_1.TO_BE_CHECKED ? (0, rxjs_1.of)(item.mimeType || 'text/html') : this.checkMimetype(data.link.uri); | ||
@@ -56,0 +70,0 @@ return mimeType.pipe((0, rxjs_1.switchMap)((type) => nucliaConnector.uploadLink(item.originalId, item.title, data.link, type, { |
@@ -85,2 +85,3 @@ import { Observable } from 'rxjs'; | ||
isAccessTokenValid(): Observable<boolean>; | ||
getGroups?: (resource: SyncItem) => Observable<string[]>; | ||
} |
@@ -23,2 +23,3 @@ import { Observable } from 'rxjs'; | ||
download(resource: SyncItem): Observable<Blob>; | ||
getGroups(resource: SyncItem): Observable<string[]>; | ||
} |
@@ -91,2 +91,7 @@ import { Observable } from 'rxjs'; | ||
export type Filters = z.infer<typeof FiltersValidator>; | ||
export declare enum ContentType { | ||
blob = "blob", | ||
link = "link", | ||
text = "text" | ||
} | ||
export interface ISyncEntity { | ||
@@ -102,2 +107,3 @@ connector: Connector; | ||
disabled?: boolean; | ||
syncSecurityGroups?: boolean; | ||
} | ||
@@ -115,2 +121,3 @@ export declare class SyncEntity { | ||
disabled?: boolean; | ||
syncSecurityGroups?: boolean; | ||
constructor(options: ISyncEntity); | ||
@@ -117,0 +124,0 @@ private setConnectorDefinition; |
{ | ||
"name": "@nuclia/sync-agent", | ||
"version": "1.2.15", | ||
"version": "1.2.16", | ||
"description": "This is a sync agent to synchronize user files from diferent sources to nuclia", | ||
@@ -28,3 +28,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@nuclia/core": "^1.14.4", | ||
"@nuclia/core": "^1.14.5", | ||
"cheerio": "^1.0.0-rc.12", | ||
@@ -31,0 +31,0 @@ "commander": "^11.1.0", |
185959
4345
21
+ Added@nuclia/core@1.24.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
- Removed@nuclia/core@1.24.1(transitive)
- Removedobject-inspect@1.13.4(transitive)
Updated@nuclia/core@^1.14.5