Используйте nuxeo client sdk для RESTClient от Angular 6

Я хочу использовать nuxeo ClientSdk для использования его REST API в моем клиенте Angular 6, но я не могу его использовать, потому что это пакет 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

imho, я неправильно выполнял процедуру импорта, так что есть идеи, как решить эту проблему?

и библиотека, которую я хочу импортировать:

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;

person Michele Spinello    schedule 19.07.2018    source источник


Ответы (1)


Вы можете взглянуть на службу, созданную CLI nuxeo при начальной загрузке проекта Angular. Короче говоря, он добавляет следующую строку при создании экземпляра клиента:

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

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