{"_id":"@ctbto/alfresco-js-api","_rev":"1-899aceb5e7d5c33df88f2811cd5dfd37","name":"@ctbto/alfresco-js-api","dist-tags":{"latest":"4.4.0"},"versions":{"4.4.0":{"name":"@ctbto/alfresco-js-api","version":"4.4.0","description":"JavaScript client library for the Alfresco REST API","author":{"name":"Alfresco Software, Ltd."},"main":"./index.js","typings":"./typings/index.d.ts","sideEffects":false,"repository":{"type":"git","url":"git+https://github.com/Alfresco/alfresco-js-api.git"},"bugs":{"url":"https://github.com/Alfresco/alfresco-js-api/issues"},"dependencies":{"event-emitter":"^0.3.5","minimatch":"3.0.4","superagent":"^6.0.0"},"license":"Apache-2.0","keywords":["alfresco"],"volta":{"node":"14.17.0"},"module":"./_esm5/index.js","es2015":"./_esm2015/index.js","homepage":"https://github.com/Alfresco/alfresco-js-api#readme","_id":"@ctbto/alfresco-js-api@4.4.0","_nodeVersion":"14.17.0","_npmVersion":"6.14.13","dist":{"integrity":"sha512-5kI+qqulFeuVBVnTJa827XLPRPNc1rG1yLRbajAp2CeeE+6dznf58MpnG7Y+cjvOyFRmcfifwgnSidZEgaUKBw==","shasum":"b6f0ae2732fea6eea93b3c20260394b964a9ab42","tarball":"https://registry.npmjs.org/@ctbto/alfresco-js-api/-/alfresco-js-api-4.4.0.tgz","fileCount":4963,"unpackedSize":13043009,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgq3qFCRA9TVsSAnZWagAAMuwQAJSCBZMdmeCcnIYs3KFZ\nNn+qo3wmXiqTLsj2KHmkS1vFe1oLYwEIj7ZC4QASzxaLzYoL/w1aJ4GB5eOC\n7pJtisVEQgpUVvpFzhOf9ZZqXfhUUASEQNahh0TnEqZCd/R2a3FkAysqXtHa\nitKa7I6+eBbN5gaEaf7TwFyiBBG1hxXgdC2Pujw3nDbXrTs00QaZ12rSGs3o\nGyS9zuyy/BGTLZnBtS3+AOjXnmwWeQBfBJU4+N4qzZjDVo/98fyoqzyoS/G+\nZ9c954dCxz9eEL/WYgdTg/YRJC+AYA1zr536bSCz6OkZKDgRi3x3LphUqS7w\n65rxpWUC/sm3DI/TX5dACsqfDTAb3QRvCX1KkKzui+h22Ssezhz+NDHd2jZx\nPYHpOo5r3usCSSvRi+SriZVvwQDKOFkOotmA5oNfRnZH75D8lDK07wnn62Wc\nF+LI907LOVMf3VbfGV7I/y7Zwi8UskozMTswENJD7rIdAJ2mz0PHvu7pnY0m\n38lrv25eoTPDdP0cohDb1EFg0Z4NxdhyDlAC39mxIqMzRpBgAz+kWGQlOa3f\nFw3nHKx96KO78eJSeDwxJZDUILHuP3UvpWuogLmpgEw5i4qnYjYH6JIXnRuO\nu0TpZysB6dV8Vv+NV+xnkFar65cLbLxyKd5ZYbo2bDSqKijbunBdbbmjSWMk\nEVR7\r\n=EzO1\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDM7/GNXL5pJmN5rPUNE87gZGxSj+WmcVQbVVHk3Q1mPQIhANW89JRZ3YaCJoc1Pz07camZxr132PO6Nfy3ItfIguUJ"}]},"_npmUser":{"name":"garthw","email":"garth@wi.llia.ms"},"directories":{},"maintainers":[{"name":"garthw","email":"garth@wi.llia.ms"},{"name":"kaindad","email":"kainda.daka@ctbto.org"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/alfresco-js-api_4.4.0_1621850756615_0.9247150487737235"},"_hasShrinkwrap":false}},"time":{"created":"2021-05-24T10:05:56.316Z","4.4.0":"2021-05-24T10:05:56.872Z","modified":"2022-04-05T02:03:52.426Z"},"maintainers":[{"name":"garthw","email":"garth@wi.llia.ms"},{"name":"kaindad","email":"kainda.daka@ctbto.org"}],"description":"JavaScript client library for the Alfresco REST API","homepage":"https://github.com/Alfresco/alfresco-js-api#readme","keywords":["alfresco"],"repository":{"type":"git","url":"git+https://github.com/Alfresco/alfresco-js-api.git"},"author":{"name":"Alfresco Software, Ltd."},"bugs":{"url":"https://github.com/Alfresco/alfresco-js-api/issues"},"license":"Apache-2.0","readme":"# Alfresco JavaScript API Client\n\n| branch  | status                                                                                                                               |\n| ------- | ------------------------------------------------------------------------------------------------------------------------------------ |\n| master  | [![Build Status](https://travis-ci.com/Alfresco/alfresco-js-api.svg?branch=master)](https://travis-ci.com/Alfresco/alfresco-js-api)  |\n| develop | [![Build Status](https://travis-ci.com/Alfresco/alfresco-js-api.svg?branch=develop)](https://travis-ci.com/Alfresco/alfresco-js-api) |\n\n<p>\n  <a title='Gitter chat' href=\"https://gitter.im/Alfresco/api/ng2-components?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge\">\n     <img src='https://badges.gitter.im/Alfresco/api/ng2-components.svg'  alt='Gitter chat' />\n  </a>\n  <a href='https://raw.githubusercontent.com/Alfresco/dev-platform-js-api/master/LICENSE'>\n     <img src='https://img.shields.io/hexpm/l/plug.svg' alt='license' />\n  </a>\n\n</p>\n\n<p align=\"center\">\n  <img title=\"alfresco\" alt='alfresco' src='assets/alfresco.png'  width=\"280px\" height=\"150px\"></img>\n</p>\n\n---\n\n> Warning: This is a clone of the official [@alfresco/js-api](https://www.npmjs.com/package/@alfresco/js-api) which fixes TypeScript support. Unless you are experiencing typescript errors with the official version, it's strongly recommended that you use the official version.\n\n---\n\nThis project provides a JavaScript client API into the Alfresco REST API and Activiti REST API.\n\n<!-- markdown-toc start - Don't edit this section.  npm run toc to generate it-->\n\n<!-- toc -->\n\n-   [Full documentation of all the methods of each API](#full-documentation-of-all-the-methods-of-each-api)\n-   [Prerequisites](#prerequisites)\n-   [Node](#node)\n-   [Install](#install)\n-   [Authentication JS-API](#authentication-js-api)\n    -   [Login](#login)\n        -   [Login with Username and Password BPM and ECM](#login-with-username-and-password-bpm-and-ecm)\n            -   [Example](#example)\n        -   [Login with Username and Password ECM](#login-with-username-and-password-ecm)\n            -   [Example](#example-1)\n        -   [Login with ticket](#login-with-ticket)\n            -   [Login with ticket ECM](#login-with-ticket-ecm)\n                -   [Example](#example-2)\n            -   [Login with ticket ECM/BPM as parameter in the constructor](#login-with-ticket-ecmbpm-as-parameter-in-the-constructor)\n                -   [Example](#example-3)\n        -   [Login with Username and Password BPM](#login-with-username-and-password-bpm)\n            -   [Example](#example-4)\n        -   [Login with OAUTH2 Alfresco authorization server](#login-with-oauth2-alfresco-authorization-server)\n            -   [Implicit Flow](#implicit-flow)\n                -   [oauth2 properties](#oauth2-properties)\n                -   [Events](#events)\n                -   [Example](#example-5)\n                -   [Example skip login form (implicitFlow)](#example-skip-login-form-implicitflow)\n            -   [Password Flow](#password-flow)\n                -   [Example](#example-6)\n                -   [Example](#example-7)\n    -   [Logout](#logout)\n        -   [Example](#example-8)\n    -   [isLoggedIn](#isloggedin)\n        -   [Example](#example-9)\n    -   [Get tickets](#get-tickets)\n    -   [Events login/logout](#events-loginlogout)\n        -   [Example](#example-10)\n-   [Custom Endpoint](#custom-endpoint)\n    -   [Example](#example-11)\n-   [Error Events](#error-events)\n    -   [Example](#example-12)\n-   [ECM Example](#ecm-example)\n-   [BPM Example](#bpm-example)\n-   [Legacy Endpoint porting (ver 2.x.x)](#legacy-endpoint-porting-ver-2xx)\n-   [Development](#development)\n\n<!-- tocstop -->\n\n<!-- markdown-toc end -->\n\n# Full documentation of all the methods of each API\n\n-   [Authentication Api](/src/api/auth-rest-api)\n-   [Content Api](/src/api/content-rest-api)\n-   [Model Api](/src/api/model-rest-api)\n-   [Process Api (APS 1.X)](/src/api-legacy/activiti-rest-api)\n-   [Process Api (AAE)](/src/api/activiti-rest-api)\n-   [Search Api](/src/api/search-rest-api)\n-   [Governance Classification Api](/src/api/gs-classification-rest-api)\n-   [Governance Core Api](/src/api/gs-core-rest-api)\n-   [Discovery Content API](/src/api/discovery-rest-api)\n\n# Prerequisites\n\nThe minimal supported versions are:\n\n-   Alfresco Platform Repository: version [5.2.a-EA](https://wiki.alfresco.com/wiki/Community_file_list_201606-EA) or newer\n-   Activiti: 1.5\n-   Node.js ([Long Term Support](https://nodejs.org/en/) version)\n\n# Installing\n\nUsing NPM:\n\n```sh\nnpm install @alfresco/js-api\n```\n\nUsing Yarn:\n\n```sh\nyarn add @alfresco/js-api\n```\n\n# Authentication JS-API\n\n## Login\n\nAlfrescoApi({alfrescoHost, activitiHost, contextRoot, ticket});\n\n| Property        | Description                                                                                                                                         | default value         |\n| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |\n| hostEcm         | (Optional value The Ip or Name of the host where your Alfresco instance is running )                                                                | http://127.0.0.1:8080 |\n| hostBpm         | (Optional value The Ip or Name of the host where your Activiti instance is running )                                                                | http://127.0.0.1:9999 |\n| authType        | (Optional value can be 'BASIC' or 'OAUTH')                                                                                                          | 'BASIC'               |\n| oauth2          | (Optional configuration for SSO)                                                                                                                    |                       |\n| contextRoot     | (Optional value that define the context Root of the Alfresco ECM API default value is alfresco )                                                    | alfresco              |\n| contextRootBpm  | (Optional value that define the context Root of the Activiti API default value is activiti-app )                                                    | alfresco              |\n| tenant          | (Optional value needed in case of multi tenant content service)                                                                                     | '-default-'           |\n| 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              |\n| ticket          | (Optional only if you want login with the ticket see example below)                                                                                 |                       |\n| disableCsrf     | To disable CSRF Token to be submitted. Only for Activiti call.                                                                                      | false                 |\n| withCredentials | (Optional configuration for SSO, requires CORS on ECM)                                                                                              | false                 |\n\n### Login with Username and Password BPM and ECM\n\n#### Example\n\n```javascript\nconst alfrescoApi = new AlfrescoApi({ provider: \"ALL\" });\n\nalfrescoJsApi.login(\"admin\", \"admin\").then(\n    (data) => {\n        console.log(\"API called successfully Login in  BPM and ECM performed \");\n    },\n    (error) => {\n        console.error(error);\n    }\n);\n```\n\n### Login with Username and Password ECM\n\n#### Example\n\n```javascript\nconst alfrescoJsApi = new AlfrescoApi();\n\nalfrescoJsApi.login(\"admin\", \"admin\").then(\n    (data) => {\n        console.log(\"API called successfully Login ticket:\" + data);\n    },\n    (error) => {\n        console.error(error);\n    }\n);\n\n// The output will be: API called successfully Login ticket: TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1\n```\n\n### Login with ticket\n\nIf 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\n\n#### Login with ticket ECM\n\nThis authentication validate also the ticket against the server\n\n##### Example\n\n```javascript\nconst ticket = \"TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1\";\n\nalfrescoJsApi.loginTicket(ticket).then(\n    (data) => {\n        console.log(\"valid ticket you are logged in\");\n    },\n    (error) => {\n        console.error(error);\n    }\n);\n```\n\n#### Login with ticket ECM/BPM as parameter in the constructor\n\nWith this authentication the ticket is not validated against the server\n\n##### Example\n\n```javascript\n// Login with ECM ticket\nconst alfrescoApi = new AlfrescoApi({\n    ticketEcm: \"TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1\",\n    hostEcm: \"http://127.0.0.1:8080\",\n});\n\n// Login with BPM ticket\nconst alfrescoApi = new AlfrescoApi({\n    ticketBpm: \"Basic YWRtaW46YWRtaW4=\",\n    hostBpm: \"http://127.0.0.1:9999\",\n});\n\n// Login with ECM and BPM tickets\nconst alfrescoApi = new AlfrescoApi({\n    ticketEcm: \"TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1\",\n    ticketBpm: \"Basic YWRtaW46YWRtaW4=\",\n    hostEcm: \"http://127.0.0.1:8080\",\n    hostBpm: \"http://127.0.0.1:9999\",\n});\n```\n\n### Login with Username and Password BPM\n\n#### Example\n\n```javascript\nconst alfrescoApi = new AlfrescoApi({ provider: \"BPM\" });\n\nalfrescoJsApi.login(\"admin\", \"admin\").then(\n    () => {\n        console.log(\"API called successfully Login in Activiti BPM performed \");\n    },\n    (error) => {\n        console.error(error);\n    }\n);\n```\n\n### Login with OAUTH2 Alfresco authorization server\n\n#### Implicit Flow\n\nIf your want to be redirect to the authorization server and login there you can use the implicit flow to login\n\n##### oauth2 properties\n\n| Property                | Description                                                                                                                                                                              | default value               |\n| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |\n| host                    | Your oauth2 server URL                                                                                                                                                                   | null                        |\n| clientId                | Your clientId oauth2                                                                                                                                                                     | null                        |\n| secret                  | Your secret oauth2                                                                                                                                                                       | null                        |\n| scope                   | Your scope                                                                                                                                                                               | null                        |\n| implicitFlow            | true/false                                                                                                                                                                               | false                       |\n| redirectUri             | url to be redirect after login                                                                                                                                                           | null                        |\n| redirectLogout          | url to be redirect after logout optional, if is nor present the redirectUri will be used                                                                                                 | null                        |\n| refreshTokenTimeout     | millisecond value, after how many millisecond you want refresh the token                                                                                                                 | 30000                       |\n| redirectSilentIframeUri | url to be redirect after silent refresh login                                                                                                                                            | /assets/silent-refresh.html |\n| silentLogin             | direct execute the implicit login without the need to call AlfrescoJsApi.implicitLogin() method                                                                                          | false                       |\n| publicUrls              | list of public urls that don't need authorization. It is possible too pass absolute paths and string patterns that are valid for [minimatch](https://github.com/isaacs/minimatch#readme) |\n\nThe api/js-api will automatically redirect you to the login page anf refresh the token if necessary\n\n##### Events\n\n| Property          | Description                                                                                                  | default value |\n| ----------------- | ------------------------------------------------------------------------------------------------------------ | ------------- |\n| implicit_redirect | triggered when the user is redirect to the auth server return url parameter of the redirect                  |               |\n| discovery         | triggered when all the openId discovery url phase is terminated return an object with all the discovered url |               |\n| token_issued      | triggered when a new token is issued                                                                         |               |\n\nThe api/js-api will automatically redirect you to the login page and refresh the token if necessary\n\n##### Example\n\n```javascript\nconst alfrescoApi = new AlfrescoApi({\n    oauth2: {\n        host: \"HOST_OAUTH2_SERVER\",\n        clientId: \"YOUR_CLIENT_ID\",\n        secret: \"SECRET\",\n        scope: \"openid\",\n        implicitFlow: true,\n        redirectUri: \"YOUR_HOME_APP_URL\",\n        silentRefreshTimeout: \"600000\", //Optional parameter 10 minutes default value\n    },\n    authType: \"OAUTH\",\n    provider: \"ALL\",\n});\n\nalfrescoJsApi.implicitLogin();\n```\n\n##### Example skip login form (implicitFlow)\n\n```javascript\nconst alfrescoApi = new AlfrescoApi({\n    oauth2: {\n        host: 'HOST_OAUTH2_SERVER',\n        clientId: 'YOUR_CLIENT_ID',\n        secret: 'SECRET',\n        scope: 'openid',\n        implicitFlow: true,\n        redirectUri: 'YOUR_HOME_APP_URL',\n        silentRefreshTimeout: '600000' //Optional parameter 10 minutes default value,\n        silentLogin: true,\n        publicUrls: ['PUBLIC_URL', 'URL_PATTERN']\n    },\n    authType: 'OAUTH',\n    provider: 'ALL'\n});\n```\n\n#### Password Flow\n\nIf your auth endpoint is different from the standard one \"/oauth/token\" you can override it through the property authPath\n\n##### Example\n\n```javascript\nconst alfrescoApi = new AlfrescoApi({\n    oauth2: {\n        host: \"HOST_OAUTH2_SERVER\",\n        clientId: \"YOUR_CLIENT_ID\",\n        secret: \"SECRET\",\n        authPath: \"my-custom-auth-endpoint/token\",\n    },\n    authType: \"OAUTH\",\n    provider: \"ALL\",\n});\n\nalfrescoJsApi.login(\"admin\", \"admin\").then(\n    (data) => {\n        console.log(\n            \"API called successfully Login in with authorization server performed\"\n        );\n    },\n    (error) => {\n        console.error(error);\n    }\n);\n```\n\nAfter the login if you want refresh your token you can use this call\n\n##### Example\n\n```javascript\nalfrescoJsApi.refreshToken().then(\n    (data) => {\n        console.log(\"Your token has been refreshed\");\n    },\n    (error) => {\n        console.error(error);\n    }\n);\n```\n\n## Logout\n\nlogout()\n\n### Example\n\n```javascript\nalfrescoJsApi.logout().then(\n    (data) => {\n        console.log(\"Successfully Logout\");\n    },\n    (error) => {\n        console.error(\"Possible ticket already expired\");\n    }\n);\n```\n\n## isLoggedIn\n\nisLoggedIn()\n\n> return true if you are logged in false if you are not.\n\n### Example\n\n```javascript\nconst isLoggedIn = alfrescoJsApi.isLoggedIn();\n\nif (isLoggedIn) {\n    console.log(\"You are logged in\");\n} else {\n    console.log(\"You are not logged in\");\n}\n```\n\n## Get tickets\n\n### getTicketEcm()\n\nAfter the log in you can retrieve you ECM ticket\n\n```javascript\nconst ecmTicket = alfrescoJsApi.getTicketEcm();\n\nconsole.log(\"This is your  ECM ticket  \" + ecmTicket);\n```\n\n### getTicketBpm()\n\nAfter the log in you can retrieve you BPM ticket\n\n```javascript\nconst bpmTicket = alfrescoJsApi.getTicketBpm();\n\nconsole.log(\"This is your BPM ticket \" + bpmTicket);\n```\n\n## Events login/logout\n\nThe login/logout are also an EventEmitter which you can register to listen to any of the following event types:\n\n-   unauthorized (If this event is triggered a call to the Api was unauthorized)\n-   success (If this event is triggered the login was success you can use this event > instead the login promise)\n-   logout (If this event is triggered the client is successfully logout)\n\n### Example\n\n```javascript\nalfrescoJsApi.login(\"admin\", \"admin\").on(\"unauthorized\", () => {\n    console.log(\n        \"You are unauthorized you can use this event to redirect to login\"\n    );\n});\n\nalfrescoJsApi.login(\"admin\", \"admin\").on(\"success\", () => {\n    console.log(\"Success Login\");\n});\n\nalfrescoJsApi.logout().on(\"logout\", () => {\n    console.log(\"Successfully Logout\");\n});\n```\n\n# Custom Endpoint\n\nContent service and process service has two different clients:\n\n-   AlfrescoJsApi.ProcessClient\n-   AlfrescoJsApi.ContentClient\n\nBoth client expose a method **\\*callApi**\n\n```javascript\ncallApi(\n    path: string,\n    httpMethod: string,\n    pathParams?: any,\n    queryParams?: any,\n    headerParams?: any,\n    formParams?: any,\n    bodyParam?: any,\n    contentTypes?: string[],\n    accepts?: string[],\n    returnType?: any,\n    contextRoot?: string,\n    responseType?: string\n): Promise<any>;\n```\n\nIf you want call your custom rest point in one of those two service use the corresponding client.\n\n## Example\n\n```javascript\nalfrescoJsApi.bpmClient.callApi(\n    \"/api/enterprise/app-version\",\n    \"GET\",\n    {},\n    {},\n    {},\n    {},\n    {},\n    [\"application/json\"],\n    [\"application/json\"],\n    { String: \"String\" }\n);\n```\n\n# Error Events\n\nThe api/js-api has an error handler event where you can subscribe\n\n## Example\n\n```javascript\nalfrescoJsApi.on(\"error\", (error) => {\n    console.log(error);\n});\n```\n\n# ECM Example\n\nA complete list of all the ECM methods is available here : [Content API](/src/api/content-rest-api) here you can find some common [Example](/ecm-example.md).\n\n# BPM Example\n\nA complete list of all the BPM methods is available here : [APS 2.X API](/src/api/activiti-rest-api) here you can find some common [Example](/bpm-example.md).\n\n# Legacy Endpoint porting (ver 2.x.x)\n\nSince version 3.0.0 in order to support tree shaking the JS-API has been radically redesigned.\n\nIn 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.\n\n**_Note this compatibility layer could be deleted in the next major versions of the JS-API_**\n\n```javascript\nimport { AlfrescoApiCompatibility as AlfrescoApi } from \"../src/alfrescoApiCompatibility\";\n\nconst alfrescoJsApi = new AlfrescoApi({\n    oauth2: {\n        host: \"HOST_OAUTH2_SERVER\",\n        clientId: \"YOUR_CLIENT_ID\",\n        secret: \"SECRET\",\n        authPath: \"my-custom-auth-endpoint/token\",\n    },\n    authType: \"OAUTH\",\n    provider: \"ALL\",\n});\n\nalfrescoJsApi.login(\"admin\", \"admin\").then(\n    (data) => {\n        console.log(\n            \"API called successfully Login in with authorization server performed \"\n        );\n    },\n    (error) => {\n        console.error(error);\n    }\n);\n\nalfrescoJsApi.nodes.getNodeInfo(fileOrFolderId).then(\n    (data) => {\n        console.log(\"This is the name\" + data.name);\n    },\n    (error) => {\n        console.log(\"This node does not exist\");\n    }\n);\n```\n\n# Development\n\nNodeJs versions newer that version 12 may have build errors.\n\nTo run the build\n\n```sh\nnpm run build\n```\n\nTo run the test\n\n```sh\nnpm run test\n```\n","readmeFilename":"README.md"}