Looking to integrate the Nuxeo ClientSdk with my Angular 6 client to consume its REST API, but facing issues due to the lack of typescript definitions for this JavaScript package.
Tried importing the library into my project using the following code snippet within my custom service:
import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Observable, of} from 'rxjs';
import { Http, Response , RequestOptions , Headers } from '@angular/http';
import { Data } from './model/genericData';
import * as NuxeoSdk from 'nuxeo';
const username = 'Administrator';
const password = 'Administrator';
const httpOptions = {
headers : new HttpHeaders({
'Authorization' : 'Basic ' + btoa(username + ':' + password),
'X-NXDocumentProperties' : '*'
})
};
/*const headers = new HttpHeaders();
headers.append('Authorization', 'Basic ' + btoa('Administrator:Administrator'));
headers.append('X-NXDocumentProperties', '*');*/
const baseAddr = 'http://dev2017-publicwebserver-alb-59603702.eu-west-1.elb.amazonaws.com/nuxeo/';
const serviceApiEndpoint = 'api/v1/';
const methodId = 'id/';
const childrenQuery = '/@children?';
const RootId = '1ca2e2f5-4e9e-4c98-afc6-95b467c359fc';
@Injectable({
providedIn: 'root'
})
export class NuxeoService {
constructor(private http: HttpClient) {}
getJsonById(id: string): Observable<Data> {
// this.http.get(this.baseAddr + this.methodId + id, httpOptions).subscribe(res => );
return this.http.get<Data>(baseAddr + serviceApiEndpoint + methodId + id, httpOptions);
}
getRoot(): Observable<Data> {
// this.http.get(this.baseAddr + this.methodId + id, httpOptions).subscribe(res => );
return this.http.get<Data>(baseAddr + serviceApiEndpoint + methodId + RootId, httpOptions);
}
getDomains(): Observable<Data> {
return this.http.get<Data>(baseAddr + serviceApiEndpoint + methodId + RootId + childrenQuery, httpOptions);
}
getChildrenById(id: string): Observable<Data> {
return this.http.get<Data>(baseAddr + serviceApiEndpoint + methodId + id + childrenQuery, httpOptions);
}
getNuxeoResource(): void {
const nuxeo = new NuxeoSdk({
baseURL: baseAddr,
auth: {
method: 'basic',
username: username,
password: password
}
});
nuxeo.request('path/')
.get()
.then(function (doc) {
console.log('doc-> ', doc);
});
}
}
Encountered an error while running the Angular app:
index.js:1 Uncaught ReferenceError: process is not defined
at Object../node_modules/promise-queue/index.js (index.js:1)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/nuxeo/lib/upload/batch.js (batch.js:5)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/nuxeo/lib/operation.js (operation.js:7)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/nuxeo/lib/nuxeo.js (nuxeo.js:4)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/nuxeo/lib/index.js (index.js:1)
at __webpack_require__ (bootstrap:76)
./node_modules/promise-queue/index.js @ index.js:1
__webpack_require__ @ bootstrap:76
./node_modules/nuxeo/lib/upload/batch.js @ batch.js:5
__webpack_require__ @ bootstrap:76
./node_modules/nuxeo/lib/operation.js @ operation.js:7
__webpack_require__ @ bootstrap:76
./node_modules/nuxeo/lib/nuxeo.js @ nuxeo.js:4
__webpack_require__ @ bootstrap:76
./node_modules/nuxeo/lib/index.js @ index.js:1
__webpack_require__ @ bootstrap:76
./src/app/nuxeo.service.ts @ DynamicFlatNode.ts:8
__webpack_require__ @ bootstrap:76
./src/app/app.module.ts @ app.component.ts:176
__webpack_require__ @ bootstrap:76
./src/main.ts @ environment.ts:15
__webpack_require__ @ bootstrap:76
0 @ main.ts:12
__webpack_require__ @ bootstrap:76
checkDeferredModules @ bootstrap:43
webpackJsonpCallback @ bootstrap:30
(anonymous) @ main.js:1
Seems like there's an issue in the way I'm importing the library. Any suggestions on fixing this problem?
The library I intend to import includes:
const Nuxeo = require('./nuxeo');
const Base = require('./base');
const Operation = require('./operation');
const Request = require('./request');
const Repository = require('./repository');
...
(module.exports section omitted for brevity)
...
Nuxeo.registerUnmarshaller('user', userUnmarshaller);
Nuxeo.registerUnmarshaller('group', groupUnmarshaller);
// make the WorkflowsUnmarshaller work for Nuxeo 7.10
Nuxeo.registerUnmarshaller('worflows', workflowsUnmarshaller);
module.exports = Nuxeo;