• This repository has been archived on 08/Feb/2024
  • Stars
    star
    117
  • Rank 301,828 (Top 6 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This project provides a JavaScript client API into the Alfresco REST API and Activiti REST API.

Alfresco JavaScript API Client

Gitter chat license

alfresco

This project provides a JavaScript client API into the Alfresco REST API and Activiti REST API.

Full documentation of all the methods of each API

Prerequisites

The minimal supported versions are:

Installing

Using NPM:

npm install @alfresco/js-api

Using Yarn:

yarn add @alfresco/js-api

Authentication JS-API

Login

AlfrescoApi({alfrescoHost, activitiHost, contextRoot, ticket});

Property Description default value
hostEcm (Optional value The Ip or Name of the host where your Alfresco instance is running ) http://127.0.0.1:8080
hostBpm (Optional value The Ip or Name of the host where your Activiti instance is running ) http://127.0.0.1:9999
authType (Optional value can be 'BASIC' or 'OAUTH') 'BASIC'
oauth2 (Optional configuration for SSO)
contextRoot (Optional value that define the context Root of the Alfresco ECM API default value is alfresco ) alfresco
contextRootBpm (Optional value that define the context Root of the Activiti API default value is activiti-app ) alfresco
tenant (Optional value needed in case of multi tenant content service) '-default-'
provider (Optional value default value is ECM. This parameter can accept as value ECM BPM or ALL to use the API and Login in the ECM, Activiti BPM or Both ) alfresco
ticket (Optional only if you want login with the ticket see example below)
disableCsrf To disable CSRF Token to be submitted. Only for Activiti call. false
withCredentials (Optional configuration for SSO, requires CORS on ECM) false
oauthInit (Optional, if false skip the OAuth2 initialization) true

Login with Username and Password BPM and ECM

Example

const alfrescoApi = new AlfrescoApi({ provider: 'ALL' });

alfrescoJsApi.login('admin', 'admin').then(
    data => {
        console.log('API called successfully Login in  BPM and ECM performed ');
    },
    error => {
        console.error(error);
    }
);

Login with Username and Password ECM

Example

const alfrescoJsApi = new AlfrescoApi();

alfrescoJsApi.login('admin', 'admin').then(
    data => {
        console.log('API called successfully Login ticket:' + data);
    },
    error => {
        console.error(error);
    }
);

// The output will be: API called successfully Login ticket: TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1

Login with ticket

If you already know thw ticket when you invoke the constructor you can pass it as parameter in the constructor otherwise you can call the login with ticket that will validate the ticket against the server

Login with ticket ECM

This authentication validate also the ticket against the server

Example
const ticket = 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1';

alfrescoJsApi.loginTicket(ticket).then(
    data => {
        console.log('valid ticket you are logged in');
    },
    error => {
        console.error(error);
    }
);

Login with ticket ECM/BPM as parameter in the constructor

With this authentication the ticket is not validated against the server

Example
// Login with ECM ticket
const alfrescoApi = new AlfrescoApi({
    ticketEcm:'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1',
    hostEcm:'http://127.0.0.1:8080'
});

// Login with BPM ticket
const alfrescoApi = new AlfrescoApi({
    ticketBpm: 'Basic YWRtaW46YWRtaW4=',  
    hostBpm:'http://127.0.0.1:9999'
});

// Login with ECM and BPM tickets
const alfrescoApi = new AlfrescoApi({
    ticketEcm:'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1',
    ticketBpm: 'Basic YWRtaW46YWRtaW4=',  
    hostEcm:'http://127.0.0.1:8080',  
    hostBpm:'http://127.0.0.1:9999'
});

Login with Username and Password BPM

Example

const alfrescoApi = new AlfrescoApi({ provider:'BPM' });

alfrescoJsApi.login('admin', 'admin').then(
    () => {
        console.log('API called successfully Login in Activiti BPM performed ');
    },
    error => {
        console.error(error);
    }
);

Login with OAUTH2 Alfresco authorization server

Implicit Flow

If your want to be redirect to the authorization server and login there you can use the implicit flow to login

oauth2 properties
Property Description default value
host Your oauth2 server URL null
clientId Your clientId oauth2 null
secret Your secret oauth2 null
scope Your scope null
implicitFlow true/false false
redirectUri url to be redirect after login null
redirectLogout url to be redirect after logout optional, if is nor present the redirectUri will be used null
refreshTokenTimeout millisecond value, after how many millisecond you want refresh the token 30000
redirectSilentIframeUri url to be redirect after silent refresh login /assets/silent-refresh.html
silentLogin direct execute the implicit login without the need to call AlfrescoJsApi.implicitLogin() method false
publicUrls list of public urls that don't need authorization. It is possible too pass absolute paths and string patterns. In patterns you can use * or ** wildcards. Single means that you can have anything in one part of URL for example http://some-public-url/path/* matches with http://some-public-url/path/test. Double means that you can have anything in any number of parts, for example http://some-public-url/path/** matches with http://some-public-url/path/test/some-test.
authorizationUrl authorization url, relative to the host /protocol/openid-connect/auth
tokenUrl token url, relative to the host /protocol/openid-connect/token
logoutUrl logout url, relative to the host /protocol/openid-connect/logout

The api/js-api will automatically redirect you to the login page anf refresh the token if necessary

Events
Property Description default value
implicit_redirect triggered when the user is redirect to the auth server return url parameter of the redirect
discovery triggered when all the openId discovery url phase is terminated return an object with all the discovered url
token_issued triggered when a new token is issued

The api/js-api will automatically redirect you to the login page and refresh the token if necessary

Example
const alfrescoApi = new AlfrescoApi({
    oauth2: {
        host: 'HOST_OAUTH2_SERVER',
        clientId: 'YOUR_CLIENT_ID',
        secret: 'SECRET',
        scope: 'openid',
        implicitFlow: true,
        redirectUri: 'YOUR_HOME_APP_URL',
        silentRefreshTimeout: '600000' //Optional parameter 10 minutes default value
    },
    authType: 'OAUTH',
    provider: 'ALL'
});

alfrescoJsApi.implicitLogin();
Example skip login form (implicitFlow)
const alfrescoApi = new AlfrescoApi({
    oauth2: {
        host: 'HOST_OAUTH2_SERVER',
        clientId: 'YOUR_CLIENT_ID',
        secret: 'SECRET',
        scope: 'openid',
        implicitFlow: true,
        redirectUri: 'YOUR_HOME_APP_URL',
        silentRefreshTimeout: '600000' //Optional parameter 10 minutes default value,
        silentLogin: true,
        publicUrls: ['PUBLIC_URL', 'URL_PATTERN']
    },
    authType: 'OAUTH',
    provider: 'ALL'
});

Password Flow

If your auth endpoint is different from the standard one "/oauth/token" you can override it through the property authPath

Example
const alfrescoApi = new AlfrescoApi({
    oauth2: {
        host: 'HOST_OAUTH2_SERVER',
        clientId: 'YOUR_CLIENT_ID',
        secret: 'SECRET',
        authPath:'my-custom-auth-endpoint/token'
    },
    authType: 'OAUTH',
    provider: 'ALL'
});

alfrescoJsApi.login('admin', 'admin').then(
    data => {
        console.log('API called successfully Login in with authorization server performed');
    },
    error => {
        console.error(error);
    }
);

After the login if you want refresh your token you can use this call

Example
alfrescoJsApi.refreshToken().then(
    data => {
        console.log('Your token has been refreshed');
    },
    error => {
        console.error(error);
    }
);

Logout

logout()

Example

alfrescoJsApi.logout().then(
    data => {
        console.log('Successfully Logout');
    },
    error => {
        console.error('Possible ticket already expired');
    }
);

isLoggedIn

isLoggedIn()

return true if you are logged in false if you are not.

Example

const isLoggedIn = alfrescoJsApi.isLoggedIn();

if (isLoggedIn) {
    console.log('You are logged in');
} else {
    console.log('You are not logged in');
}

Get tickets

getTicketEcm()

After the log in you can retrieve you ECM ticket

const ecmTicket = alfrescoJsApi.getTicketEcm() ;

console.log('This is your  ECM ticket  ' + ecmTicket);

getTicketBpm()

After the log in you can retrieve you BPM ticket

const bpmTicket  = alfrescoJsApi.getTicketBpm();

console.log('This is your BPM ticket ' + bpmTicket);

Events login/logout

The login/logout are also an EventEmitter which you can register to listen to any of the following event types:

  • unauthorized (If this event is triggered a call to the Api was unauthorized)
  • success (If this event is triggered the login was success you can use this event > instead the login promise)
  • logout (If this event is triggered the client is successfully logout)

Example

alfrescoJsApi.login('admin', 'admin')
    .on('unauthorized', () => {
        console.log('You are unauthorized you can use this event to redirect to login');
    });

alfrescoJsApi.login('admin', 'admin')
    .on('success', () => {
        console.log('Success Login');
    });

alfrescoJsApi.logout()
    .on('logout', () => {
        console.log('Successfully Logout');
    });

Custom Endpoint

Content service and process service has two different clients:

  • AlfrescoJsApi.ProcessClient
  • AlfrescoJsApi.ContentClient

Both client expose a method *callApi

callApi(
    path: string,
    httpMethod: string,
    pathParams?: any,
    queryParams?: any,
    headerParams?: any,
    formParams?: any,
    bodyParam?: any,
    contentTypes?: string[],
    accepts?: string[],
    returnType?: any,
    contextRoot?: string,
    responseType?: string
): Promise<any>;

If you want call your custom rest point in one of those two service use the corresponding client.

Example

alfrescoJsApi.bpmClient.callApi(
    '/api/enterprise/app-version', 'GET',
    {}, {}, {}, {}, {}, ['application/json'], ['application/json'], {'String': 'String'}
)

Error Events

The api/js-api has an error handler event where you can subscribe

Example

alfrescoJsApi.on('error', error => {
    console.log(error);
});

ECM Example

A complete list of all the ECM methods is available here : Content API here you can find some common Example.

BPM Example

A complete list of all the BPM methods is available here : APS 2.X API here you can find some common Example.

Legacy Endpoint porting (ver 2.x.x)

Since version 3.0.0 in order to support tree shaking the JS-API has been radically redesigned.

In order to help the porting to the new JS-APi version of the old project the previous syntax even if is deprecated is still supported in the compatibility layer.

Note this compatibility layer could be deleted in the next major versions of the JS-API

import { AlfrescoApiCompatibility as AlfrescoApi } from '../src/alfrescoApiCompatibility';

const alfrescoJsApi = new AlfrescoApi({
        oauth2: {
            host: 'HOST_OAUTH2_SERVER',
            clientId: 'YOUR_CLIENT_ID',
            secret: 'SECRET',
            authPath:'my-custom-auth-endpoint/token'
        },
        authType: 'OAUTH',
        provider: 'ALL'
    });

alfrescoJsApi.login('admin', 'admin').then(
    data => {
        console.log('API called successfully Login in with authorization server performed ');
    },
    error => {
        console.error(error);
    }
);

alfrescoJsApi.nodes
    .getNodeInfo(fileOrFolderId)
    .then(
        data => {
            console.log('This is the name' + data.name );
        },
        error => {
            console.log('This node does not exist');
        }
    );

Development

To run the build

npm run build

To run the test

npm run test

More Repositories

1

alfresco-ng2-components

Alfresco Angular Components
TypeScript
293
star
2

alfresco-content-app

Alfresco Content Application
TypeScript
186
star
3

alfresco-sdk

The Alfresco In-Process SDK is based on Apache Maven, includes support for rapid and standard development, testing, packaging, versioning and release of your Alfresco integration and extension projects
Java
185
star
4

acs-deployment

Alfresco Content Services containerized deployment (Helm and Docker Compose)
Smarty
174
star
5

alfresco-keycloak-theme

Theme related assets for use in the Identity Service
FreeMarker
145
star
6

alfresco-docker-installer

Generator to build Docker Compose templates to deploy Alfresco Community
JavaScript
141
star
7

alfresco-community-repo

Community Content Service Repository
Java
130
star
8

Aikau

Aikau UI framework
JavaScript
81
star
9

alfresco-sdk-samples

Alfresco SDK
72
star
10

alfresco-android-app

Java
61
star
11

alfresco-spk

Design, run, integrate Alfresco stacks
Ruby
55
star
12

acs-community-packaging

Packaging of Docker containers, war file and zip for Alfresco Content Services (Community)
Shell
55
star
13

docs-alfresco

Alfresco Documentation
HTML
51
star
14

alfresco-ios-app

Objective-C
42
star
15

share

Archive of Alfresco Share 6.0 and earlier. For the latest Community version of Share see https://github.com/Alfresco/alfresco-community-share
JavaScript
39
star
16

rest-api-explorer

Public REST API Explorer
Java
36
star
17

alfresco-identity-service

Repository for the Alfresco Identity Service
Shell
35
star
18

SearchServices

Alfresco Search Services
Java
31
star
19

alfresco-ansible-deployment

Ansible playbooks for deploying ACS
Jinja
29
star
20

generator-alfresco-adf-app

Yeoman Generator for Alfresco ADF Applications
TypeScript
28
star
21

alfresco-core

Alfresco Platform core utilities
Java
27
star
22

acs-packaging

Packaging of Docker containers, war file and zip for Alfresco Content Services (Enterprise)
Java
26
star
23

records-management

Legacy repository for Alfresco Records Management Community. New locations for latest code: AGS Community Repo (https://github.com/Alfresco/alfresco-community-repo/tree/master/amps/ags), AGS Community Share (https://github.com/Alfresco/alfresco-community-share/tree/master/amps/ags)
Java
25
star
24

gytheio

Distributed content/file investigation and manipulation framework which leverages messaging queues to perform common low-level tasks.
Java
22
star
25

alfresco-remote-api

REST API layer for Alfresco Content Services (Community and Enterprise)
Java
20
star
26

alfresco-ios-sdk

Objective-C
19
star
27

activiti-android-app

Java
17
star
28

alfresco-android-sdk

Java
17
star
29

health-care-app

TypeScript
16
star
30

activiti-ios

Repository for the Alfresco Process Services iOS app
Objective-C
16
star
31

alfresco-data-model

Java
16
star
32

alfresco-transform-core

Java
15
star
33

alfresco-indexer

A custom way to index Alfresco changes.
Java
15
star
34

alfresco-client-sdk

Alfresco Java Client SDK
Java
15
star
35

alfresco-java-sdk

Alfresco Out-Of-Process SDK for Java Developers
Java
15
star
36

activiti-client-sdk

Java
14
star
37

sweeper

A tool to check for rogue/orphaned AWS services running that cost money
Python
14
star
38

generator-ng2-alfresco-component

Yeoman Generator Angular 2 Alfresco Component
JavaScript
14
star
39

alfresco-ssl-generator

This repository contains the Dockerfile used to create the keystores, truststores and certificates required to configure SSL/TLS Mutual Authentication between different services of the Alfresco Digital Business Platform: Repository, SOLR and Zeppelin.
Shell
14
star
40

charts

Helm repository for Alfresco Kubernetes Charts. Please use https://kubernetes-charts.alfresco.com/stable as the helm repo.
HTML
13
star
41

alfresco-extension-inspector

Analyse Alfresco extensions for compliance with our best practices and recommendations for upgrade safety
Java
12
star
42

spring-social-alfresco

Spring Social plugin for Alfresco.
Java
11
star
43

activiti-contract-mgmt-sample

Sample contract management app built using Activiti
Python
8
star
44

alfresco-build-tools

Shared GitHub Actions and pre-commit configs plus some docs
Shell
8
star
45

jmxdump-analyzer

The JMXDump Analyser Utility is a small, self-contained JavaFX application which allows you to open an Alfresco 'JMX dump file' and will split the content in manageable tabs allowing for more easily understanding the information. Highlighting the important stuff first and then breaking down the settings into the relevant topics, the utility makes JMX dumps much easier to read.
Java
8
star
46

alfresco-process-infrastructure-deployment

Helm chart to deploy the AAE infrastructure
Shell
7
star
47

alfresco-docker-base-java

Alfresco base Java image
Dockerfile
7
star
48

alfresco-helloworld-transformer

Java
7
star
49

alfresco-community-share

Alfresco Share
JavaScript
7
star
50

googledrive

Java
7
star
51

alfresco-docker-base-tomcat

Alfresco base Tomcat image
Dockerfile
7
star
52

alfresco-server-root

Java
6
star
53

docs-activiti-enterprise

This repository contains the documentation for Alfresco Activiti Enterprise
6
star
54

alfresco-ui-strings

6
star
55

acs-ingress

Shell
6
star
56

alfresco-bm-manager

Alfresco Benchmark framework, utilities and load tests: a scalable load test suite
Java
6
star
57

Alfresco-NFS

Alfresco-NFS
Java
5
star
58

alfresco-trashcan-cleaner-module

Java
5
star
59

alfresco-mobile-workspace-ios

Swift
5
star
60

alfresco-appcelerator-sdk

Appcelerator Titanium Modules for Android and iOS SDKs
Objective-C
5
star
61

collaborating-with-alfresco

5
star
62

alfresco-tas-utility

Utility classes for TAS framework
Java
5
star
63

alfresco-docker-activemq

ActiveMQ image for Alfresco DBP
Dockerfile
5
star
64

alfresco-file-transfer-receiver

Java
5
star
65

alfresco-tas-restapi

This project has been merged into alfresco-community-repo. See https://github.com/Alfresco/alfresco-community-repo/tree/master/packaging/tests/tas-restapi
Java
5
star
66

surf-webscripts

Alfresco's Surf Web Scripts
Java
4
star
67

opencmis-extension

Java
4
star
68

alfresco-mobile-workspace-android

Kotlin
4
star
69

alfresco-greenmail

Java
4
star
70

alfresco-lambda-java-utils

Collection of utility classes for Java based Lambda functions.
Java
4
star
71

aws-auto-tag

Lambda triggered by CloudWatch Events to add an owner tag to new resources
Java
4
star
72

Sync-ldtp

Automated test Api project for all the desktop actions for applications like Notepad , office in both windows and Mac
Java
4
star
73

explorer

Legacy Explorer interface for Alfresco Community Edition
JavaScript
3
star
74

surf

Alfresco's Surf framework
Java
3
star
75

alfresco-process-services-examples

Java
3
star
76

alfresco-mbeans

MBeans utility code for the Alfresco Platform
Java
3
star
77

alfresco-super-pom

Alfresco generic, corporate POM file for Maven builds
Shell
3
star
78

alfresco-rest-authn-java-client

Alfresco Identity Service Java Client
Java
3
star
79

postman-collections

Postman Collections for Alfresco v1 REST APIs
3
star
80

sales-translations-example-app

Example app using Activiti and ECM components from the Angular2 app components library
TypeScript
3
star
81

alfresco-xml-factory

XML Factory to address security issues
Java
3
star
82

alfresco-ios-swift-api

Swift
3
star
83

alfresco-acs-workshops

Alfresco Content Service Workshops repository
Java
3
star
84

acme

acme for letsencrypt
Shell
3
star
85

alfresco-tas-webdav

Java
2
star
86

alfresco-process-application-deployment

Helm chart to deploy a single AAE application
Makefile
2
star
87

rest-api-bck

Repository for public REST API BCK tests
2
star
88

alfresco-anaxes-hello-world-ui

TypeScript
2
star
89

alfresco-android-kotlin-api

Kotlin
2
star
90

alfresco-legacy-lucene

Java
2
star
91

alfresco-tas-ftp

Java
2
star
92

alfresco-bm-load-users

Java
2
star
93

alfresco-solrclient

2
star
94

tutorials

2
star
95

arch-map

The Alfresco Architecture Map, containing information about how Alfresco is constructed.
2
star
96

alfresco-text-gen

Text generation library for general use during load and benchmark testing.
Java
2
star
97

alfresco-lambda-empty-s3-bucket

Lambda function that can be used in a CloudFormation template to empty an S3 bucket.
Java
2
star
98

alfresco-mmt

2
star
99

alfresco-tas-cmis

This project has been merged into alfresco-community-repo. See https://github.com/Alfresco/alfresco-community-repo/tree/master/packaging/tests/tas-cmis
Java
2
star
100

p6spy-checker

A small class to parse through some p6spy output and isolate the longest running queries
Java
2
star