我想使用 nuxeo ClientSdk 在我的 Angular 6 客户端中使用它的 REST api,但我不能使用它,因为这是一个 javascript 包,并且它没有任何 typescript 的类型定义。
但是,我尝试在我的自定义服务中使用此导入语句将这个库包含在我的项目中:
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);
});
}
}
问题是,当我运行这个角度应用程序时,发生了这个错误:
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
恕我直言,我一直在做错误的导入程序,所以有什么想法可以解决这个问题吗?
我要导入的库是:
const Nuxeo = require('./nuxeo');
const Base = require('./base');
const Operation = require('./operation');
const Request = require('./request');
const Repository = require('./repository');
const Document = require('./document');
const BatchUpload = require('./upload/batch');
const Blob = require('./blob');
const BatchBlob = require('./upload/blob');
const Users = require('./user/users');
const User = require('./user/user');
const Groups = require('./group/groups');
const Group = require('./group/group');
const Directory = require('./directory/directory');
const DirectoryEntry = require('./directory/entry');
const Workflows = require('./workflow/workflows');
const Workflow = require('./workflow/workflow');
const Task = require('./workflow/task');
const constants = require('./deps/constants');
const Promise = require('./deps/promise');
const {
basicAuthenticator,
tokenAuthenticator,
bearerTokenAuthenticator,
portalAuthenticator,
} = require('./auth/auth');
const {
documentUnmarshaller,
documentsUnmarshaller,
workflowUnmarshaller,
workflowsUnmarshaller,
taskUnmarshaller,
tasksUnmarshaller,
directoryEntryUnmarshaller,
directoryEntriesUnmarshaller,
userUnmarshaller,
groupUnmarshaller,
} = require('./unmarshallers/unmarshallers');
const NuxeoVersions = require('./nuxeo-versions');
const { SERVER_VERSIONS } = require('./server-version');
const oauth2 = require('./auth/oauth2');
const pkg = require('../package.json');
Nuxeo.Base = Base;
Nuxeo.Operation = Operation;
Nuxeo.Request = Request;
Nuxeo.Repository = Repository;
Nuxeo.Document = Document;
Nuxeo.BatchUpload = BatchUpload;
Nuxeo.Blob = Blob;
Nuxeo.BatchBlob = BatchBlob;
Nuxeo.Users = Users;
Nuxeo.User = User;
Nuxeo.Groups = Groups;
Nuxeo.Group = Group;
Nuxeo.Directory = Directory;
Nuxeo.DirectoryEntry = DirectoryEntry;
Nuxeo.Workflows = Workflows;
Nuxeo.Workflow = Workflow;
Nuxeo.Task = Task;
Nuxeo.constants = constants;
Nuxeo.version = pkg.version;
// expose Nuxeo versions
Nuxeo.VERSIONS = NuxeoVersions;
// expose Nuxeo Server versions
Nuxeo.SERVER_VERSIONS = SERVER_VERSIONS;
Nuxeo.oauth2 = oauth2;
Nuxeo.promiseLibrary(Promise);
// register default authenticators
Nuxeo.registerAuthenticator('basic', basicAuthenticator);
Nuxeo.registerAuthenticator('token', tokenAuthenticator);
Nuxeo.registerAuthenticator('bearerToken', bearerTokenAuthenticator);
Nuxeo.registerAuthenticator('portal', portalAuthenticator);
// register default unmarshallers
Nuxeo.registerUnmarshaller('document', documentUnmarshaller);
Nuxeo.registerUnmarshaller('documents', documentsUnmarshaller);
Nuxeo.registerUnmarshaller('workflow', workflowUnmarshaller);
Nuxeo.registerUnmarshaller('workflows', workflowsUnmarshaller);
Nuxeo.registerUnmarshaller('task', taskUnmarshaller);
Nuxeo.registerUnmarshaller('tasks', tasksUnmarshaller);
Nuxeo.registerUnmarshaller('directoryEntry', directoryEntryUnmarshaller);
Nuxeo.registerUnmarshaller('directoryEntries', directoryEntriesUnmarshaller);
Nuxeo.registerUnmarshaller('user', userUnmarshaller);
Nuxeo.registerUnmarshaller('group', groupUnmarshaller);
// make the WorkflowsUnmarshaller work for Nuxeo 7.10
Nuxeo.registerUnmarshaller('worflows', workflowsUnmarshaller);
module.exports = Nuxeo;