Javascript 通过Angular 6为RESTClient使用nuxeo客户端sdk

Javascript 通过Angular 6为RESTClient使用nuxeo客户端sdk,javascript,angular,typescript,error-log,nuxeo,Javascript,Angular,Typescript,Error Log,Nuxeo,我想在Angular 6客户端中使用nuxeo ClientSdk来使用它的REST api,但我不能使用它,因为这是一个javascript包,并且它没有任何类型脚本的定义 但是,我试图在我的客户服务中使用此导入语句将此库包括在我的项目中: import { Injectable } from '@angular/core'; import {HttpClient, HttpHeaders} from '@angular/common/http'; import {Observable, of

我想在Angular 6客户端中使用nuxeo ClientSdk来使用它的REST api,但我不能使用它,因为这是一个javascript包,并且它没有任何类型脚本的定义

但是,我试图在我的客户服务中使用此导入语句将此库包括在我的项目中:

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);
      });
  }
}
我怎么把进口手续弄错了,有没有办法解决这个问题

我想导入的库是:

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;

您可以在引导角度项目时查看nuxeo CLI生成的服务。 简而言之,在实例化客户机时,它添加了以下行:

  Object.getOwnPropertyNames(Nuxeo.prototype).forEach(name => {
      if (/^_|constructor/.test(name)) {
          return;
      }

      NuxeoService.prototype[name] = function (...args: any[]) {
          return nuxeo[name].apply(nuxeo, args);
      };
  });
  Object.getOwnPropertyNames(Nuxeo.prototype).forEach(name => {
      if (/^_|constructor/.test(name)) {
          return;
      }

      NuxeoService.prototype[name] = function (...args: any[]) {
          return nuxeo[name].apply(nuxeo, args);
      };
  });