[PRODENG-211] integrate JS-API with monorepo (part 1) (#9081)

* integrate JS-API with monorepo

* [ci:force] fix token issue

[ci:force] migrate docs folder

[ci:force] clean personal tokens

* [ci:force] gha workflow support

* [ci:force] npm publish target

* fix js-api test linting

* [ci:force] fix test linting, mocks, https scheme

* [ci:force] fix https scheme

* [ci:force] typescript mappings

* [ci:force] update scripts

* lint fixes

* linting fixes

* fix linting

* [ci:force] linting fixes

* linting fixes

* [ci:force] remove js-api upstream and corresponding scripts

* [ci:force] jsdoc fixes

* fix jsdoc linting

* [ci:force] jsdoc fixes

* [ci:force] jsdoc fixes

* jsdoc fixes

* jsdoc fixes

* jsdoc fixes

* [ci:force] fix jsdoc

* [ci:force] reduce code duplication

* replace 'chai' expect with node.js assert

* replace 'chai' expect with node.js assert

* [ci:force] remove chai and chai-spies for js-api testing

* [ci:force] cleanup and fix imports

* [ci:force] fix linting

* [ci:force] fix unit test

* [ci:force] fix sonar linting findings

* [ci:force] switch activiti api models to interfaces (-2.5% reduction of bundle)

* [ci:force] switch activiti api models to interfaces

* [ci:force] switch AGS api models to interfaces

* [ci:force] switch AGS api models to interfaces

* [ci:force] switch search api models to interfaces

* [ci:force] switch content api models to interfaces where applicable
This commit is contained in:
Denys Vuika
2023-11-21 10:27:51 +00:00
committed by GitHub
parent 804fa2ffd4
commit ea2c0ce229
1334 changed files with 82605 additions and 1068 deletions

View File

@@ -0,0 +1,56 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ApiClient } from '../../../api-clients/api-client';
import { LegacyHttpClient, RequestOptions } from '../../../api-clients/http-client.interface';
import { AlfrescoApiType, LegacyTicketApi } from '../../../to-deprecate/alfresco-api-type';
export abstract class BaseApi extends ApiClient {
protected declare httpClient: LegacyHttpClient & LegacyTicketApi;
/** @deprecated */
constructor(legacyApi?: AlfrescoApiType);
constructor(httpClient: LegacyHttpClient & LegacyTicketApi);
constructor(httpClient?: AlfrescoApiType | (LegacyHttpClient & LegacyTicketApi)) {
super(httpClient as AlfrescoApiType);
}
// TODO: Find a way to remove this hack from the legacy version :/
get apiClientPrivate(): LegacyHttpClient & LegacyTicketApi {
return this.httpClient ?? this.alfrescoApi.contentPrivateClient;
}
override get apiClient(): LegacyHttpClient & LegacyTicketApi {
return this.httpClient ?? this.alfrescoApi.contentClient;
}
override post<T = any>(options: RequestOptions): Promise<T> {
return this.apiClientPrivate.post<T>(options);
}
override put<T = any>(options: RequestOptions): Promise<T> {
return this.apiClientPrivate.put<T>(options);
}
override get<T = any>(options: RequestOptions): Promise<T> {
return this.apiClientPrivate.get<T>(options);
}
override delete<T = void>(options: RequestOptions): Promise<T> {
return this.apiClientPrivate.delete(options);
}
}

View File

@@ -0,0 +1,58 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ClassDescription } from '../model/classDescription';
import { BaseApi } from './base.api';
/**
* Constructs a new ClassesApi.
*/
export class ClassesApi extends BaseApi {
/**
* Gets the class information for the specified className.
*
* @param className The identifier of the class.
* @returns a Promise, with data of type ClassDescription
*/
getClass(className: string): Promise<ClassDescription> {
// verify the required parameter 'className' is set
if (className === undefined || className === null) {
throw new Error(`Missing param 'className' in getClass`);
}
return this.get<ClassDescription>({
path: '/api/classes/{className}',
pathParams: { className },
returnType: ClassDescription,
contextRoot: this.apiClientPrivate.config.contextRoot + '/s'
});
}
getSubclasses(className: string): Promise<ClassDescription[]> {
// verify the required parameter 'className' is set
if (className === undefined || className === null) {
throw new Error(`Missing param 'className'`);
}
return this.get({
path: `/api/classes/{className}/subclasses`,
pathParams: { className },
returnType: ClassDescription,
contextRoot: this.apiClientPrivate.config.contextRoot + '/s'
});
}
}

View File

@@ -0,0 +1,142 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { BaseApi } from './base.api';
export class ContentApi extends BaseApi {
/**
* Get thumbnail URL for the given nodeId
*
* @param nodeId The ID of the document node
* @param [attachment=false] Retrieve content as an attachment for download
* @param [ticket] Custom ticket to use for authentication
* @returns The URL address pointing to the content.
*/
getDocumentThumbnailUrl(nodeId: string, attachment?: boolean, ticket?: string): string {
return this.apiClient.basePath + '/nodes/' + nodeId +
'/renditions/doclib/content' +
'?attachment=' + (attachment ? 'true' : 'false') +
this.apiClient.getAlfTicket(ticket);
}
/**
* Get preview URL for the given nodeId
*
* @param nodeId The ID of the document node
* @param [attachment=false] Retrieve content as an attachment for download
* @param [ticket] Custom ticket to use for authentication
* @returns The URL address pointing to the content.
*/
getDocumentPreviewUrl(nodeId: string, attachment?: boolean, ticket?: string): string {
return this.apiClient.basePath + '/nodes/' + nodeId +
'/renditions/imgpreview/content' +
'?attachment=' + (attachment ? 'true' : 'false') +
this.apiClient.getAlfTicket(ticket);
}
/**
* Get content URL for the given nodeId
*
* @param nodeId The ID of the document node
* @param [attachment=false] Retrieve content as an attachment for download
* @param [ticket] Custom ticket to use for authentication
* @returns The URL address pointing to the content.
*/
getContentUrl(nodeId: string, attachment?: boolean, ticket?: string): string {
return this.apiClient.basePath + '/nodes/' + nodeId +
'/content' +
'?attachment=' + (attachment ? 'true' : 'false') +
this.apiClient.getAlfTicket(ticket);
}
/**
* Get rendition URL for the given nodeId
*
* @param nodeId The ID of the document node
* @param encoding of the document
* @param [attachment=false] retrieve content as an attachment for download
* @param [ticket] Custom ticket to use for authentication
* @returns The URL address pointing to the content.
*/
getRenditionUrl(nodeId: string, encoding: string, attachment?: boolean, ticket?: string): string {
return this.apiClient.basePath + '/nodes/' + nodeId +
'/renditions/' + encoding + '/content' +
'?attachment=' + (attachment ? 'true' : 'false') +
this.apiClient.getAlfTicket(ticket);
}
/**
* Get version's rendition URL for the given nodeId
*
* @param nodeId The ID of the document node
* @param versionId The ID of the version
* @param encoding of the document
* @param [attachment=false] retrieve content as an attachment for download
* @param [ticket] Custom ticket to use for authentication
* @returns The URL address pointing to the content.
*/
getVersionRenditionUrl(nodeId: string, versionId: string, encoding: string, attachment?: boolean, ticket?: string): string {
return this.apiClient.basePath + '/nodes/' + nodeId + '/versions/' + versionId +
'/renditions/' + encoding + '/content' +
'?attachment=' + (attachment ? 'true' : 'false') +
this.apiClient.getAlfTicket(ticket);
}
/**
* Get content URL for the given nodeId and versionId
*
* @param nodeId The ID of the document node
* @param versionId The ID of the version
* @param [attachment=false] Retrieve content as an attachment for download
* @param [ticket] Custom ticket to use for authentication
* @returns The URL address pointing to the content.
*/
getVersionContentUrl(nodeId: string, versionId: string, attachment?: boolean, ticket?: string): string {
return this.apiClient.basePath + '/nodes/' + nodeId +
'/versions/' + versionId + '/content' +
'?attachment=' + (attachment ? 'true' : 'false') +
this.apiClient.getAlfTicket(ticket);
}
/**
* Get content url for the given shared link id
*
* @param linkId - The ID of the shared link
* @param [attachment=false] Retrieve content as an attachment for download
* @returns The URL address pointing to the content.
*/
getSharedLinkContentUrl(linkId: string, attachment?: boolean): string {
return this.apiClient.basePath + '/shared-links/' + linkId +
'/content' +
'?attachment=' + (attachment ? 'true' : 'false');
}
/**
* Gets the rendition content for file with shared link identifier sharedId.
*
* @param sharedId - The identifier of a shared link to a file.
* @param renditionId - The name of a thumbnail rendition, for example doclib, or pdf.
* @param [attachment=false] Retrieve content as an attachment for download
* @returns The URL address pointing to the content.
*/
getSharedLinkRenditionUrl(sharedId: string, renditionId: string, attachment?: boolean): string {
return this.apiClient.basePath + '/shared-links/' + sharedId +
'/renditions/' + renditionId + '/content' +
'?attachment=' + (attachment ? 'true' : 'false');
}
}

View File

@@ -0,0 +1,577 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { PaginatedList, PaginatedEntries } from '../model/pagination';
import { BaseApi } from './base.api';
import { throwIfNotDefined } from '../../../assert';
export interface CustomModel {
name: string;
namespacePrefix: string;
description: string;
author: string;
namespaceUri: string;
status: 'ACTIVE' | 'DRAFT';
}
export interface CustomType {
name?: string;
parentName?: string;
prefixedName?: string;
description?: string;
properties?: CustomModelProperty[];
title?: string;
}
export interface CustomAspect {
description?: string;
name?: string;
parentName?: string;
prefixedName?: string;
properties?: CustomModelProperty[];
title?: string;
}
export interface CustomModelProperty {
name?: string;
prefixedName?: string;
title?: string;
dataType?: string;
facetable?: 'FALSE' | 'TRUE';
indexTokenisationMode?: 'FALSE' | 'TRUE';
constraints?: CustomModelPropertyConstraint[];
multiValued?: boolean;
mandatoryEnforced?: boolean;
mandatory?: boolean;
indexed?: boolean;
}
export interface CustomModelPropertyConstraint {
name: string;
prefixedName: string;
type: string;
parameters: any[];
}
/**
* Constructs a new CustomModelApi.
*/
export class CustomModelApi extends BaseApi {
private = true;
/**
* create Custom Model
*/
createCustomModel(status: string, description: string, name: string, namespaceUri: string, namespacePrefix: string, author?: string): Promise<{ entry: CustomModel }> {
throwIfNotDefined(namespaceUri, 'namespaceUri');
throwIfNotDefined(namespacePrefix, 'namespacePrefix');
const bodyParam = {
status,
description,
name,
namespaceUri,
namespacePrefix,
author
};
return this.post({
path: 'cmm',
bodyParam
});
}
/**
* Create a custom type
*/
createCustomType(modelName: string, name: string, parentName?: string, title?: string, description?: string): Promise<{ entry: CustomType }> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(name, 'name');
const bodyParam = {
name,
parentName,
title,
description
};
const pathParams = {
modelName
};
return this.post({
path: 'cmm/{modelName}/types',
bodyParam,
pathParams
});
}
/**
* Create a custom aspect
*/
createCustomAspect(modelName: string, name: string, parentName?: string, title?: string, description?: string): Promise<any> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(name, 'name');
const bodyParam = {
name,
parentName,
title,
description
};
const pathParams = {
modelName
};
return this.post({
path: 'cmm/{modelName}/aspects',
bodyParam,
pathParams
});
}
/**
* Create a custom constraint
*/
createCustomConstraint(modelName: string, name: string, type: string, parameters?: any): Promise<any> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(type, 'type');
throwIfNotDefined(name, 'name');
const bodyParam = {
name,
type,
parameters
};
const pathParams = {
modelName
};
return this.post({
path: 'cmm/{modelName}/constraints',
bodyParam,
pathParams
});
}
/**
* Activate the custom model
*/
activateCustomModel(modelName: string): Promise<{ entry: CustomModel }> {
throwIfNotDefined(modelName, 'modelName');
const bodyParam = {
status: 'ACTIVE'
};
const pathParams = {
modelName
};
return this.put({
path: 'cmm/{modelName}?select=status',
bodyParam,
pathParams
});
}
/**
* Deactivate the custom model
*/
deactivateCustomModel(modelName: string): Promise<{ entry: CustomModel }> {
throwIfNotDefined(modelName, 'modelName');
const bodyParam = {
status: 'DRAFT'
};
const pathParams = {
modelName
};
return this.put({
path: 'cmm/{modelName}?select=status',
bodyParam,
pathParams
});
}
/**
* Add property into an existing aspect
*/
addPropertyToAspect(modelName: string, aspectName: string, properties?: CustomModelProperty[]): Promise<CustomAspect> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(aspectName, 'aspectName');
const bodyParam = {
name: aspectName,
properties
};
const pathParams = {
modelName,
aspectName
};
return this.put({
path: 'cmm/{modelName}/aspects/{aspectName}?select=props',
bodyParam,
pathParams
});
}
/**
* Add Property into an existing type
*/
addPropertyToType(modelName: string, typeName: string, properties?: CustomModelProperty[]): Promise<CustomType> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(typeName, 'typeName');
const bodyParam = {
name: typeName,
properties
};
const pathParams = {
modelName,
typeName
};
return this.put({
path: 'cmm/{modelName}/types/{typeName}?select=props',
bodyParam,
pathParams
});
}
/**
* Edit an existing custom model
*/
updateCustomModel(modelName: string, description?: string, namespaceUri?: string, namespacePrefix?: string, author?: string): Promise<any> {
throwIfNotDefined(modelName, 'modelName');
const bodyParam = {
name: modelName,
description,
namespaceUri,
namespacePrefix,
author
};
const pathParams = {
modelName
};
return this.put({
path: 'cmm/{modelName}',
bodyParam,
pathParams
});
}
/**
* Edit an existing custom model type
*/
updateCustomType(modelName: string, typeName: string, description?: string, parentName?: string, title?: string): Promise<any> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(typeName, 'typeName');
const bodyParam = {
name: typeName,
parentName,
title,
description
};
const pathParams = {
modelName,
typeName
};
return this.put({
path: 'cmm/{modelName}/types/{typeName}',
bodyParam,
pathParams
});
}
/**
* Edit an existing custom model aspect
*/
updateCustomAspect(modelName: string, aspectName: string, description?: string, parentName?: string, title?: string): Promise<any> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(aspectName, 'aspectName');
const bodyParam = {
name: aspectName,
parentName,
title,
description
};
const pathParams = {
modelName,
aspectName
};
return this.put({
path: 'cmm/{modelName}/aspects/{aspectName}',
bodyParam,
pathParams
});
}
/**
* Get all custom models
*/
getAllCustomModel(): Promise<PaginatedEntries<CustomModel>> {
return this.get({
path: 'cmm'
});
}
/**
* Get custom model
*/
getCustomModel(modelName: string, queryParams?: any): Promise<{ entry: CustomModel }> {
throwIfNotDefined(modelName, 'modelName');
const pathParams = {
modelName
};
return this.get({
path: 'cmm/{modelName}',
pathParams,
queryParams
});
}
/**
* Get all custom model types
*/
getAllCustomType(modelName: string): Promise<PaginatedList<CustomType>> {
throwIfNotDefined(modelName, 'modelName');
const pathParams = {
modelName
};
return this.get({
path: 'cmm/{modelName}/types',
pathParams
});
}
/**
* Get custom model type
*/
getCustomType(modelName: string, typeName?: string, queryParams?: any): Promise<{ entry: CustomType }> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(typeName, 'typeName');
const pathParams = {
modelName,
typeName
};
return this.get({
path: 'cmm/{modelName}/types/{typeName}',
pathParams,
queryParams
});
}
/**
* Get all custom model aspect
*/
getAllCustomAspect(modelName: string, queryParams?: any): Promise<PaginatedList<CustomAspect>> {
throwIfNotDefined(modelName, 'modelName');
const pathParams = {
modelName
};
return this.get({
path: 'cmm/{modelName}/aspects',
pathParams,
queryParams
});
}
/**
* Get custom model aspect
*/
getCustomAspect(modelName: string, aspectName: string, queryParams?: any): Promise<{ entry: CustomAspect }> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(aspectName, 'aspectName');
const pathParams = {
modelName,
aspectName
};
return this.get({
path: 'cmm/{modelName}/aspects/{aspectName}',
pathParams,
queryParams
});
}
/**
* Get all custom model defined constraints
*/
getAllCustomConstraints(modelName: string, queryParams?: any): Promise<any> {
throwIfNotDefined(modelName, 'modelName');
const pathParams = {
modelName
};
return this.get({
path: 'cmm/{modelName}/constraints',
pathParams,
queryParams
});
}
/**
* Get custom model defined constraints
*/
getCustomConstraints(modelName: string, constraintName: string, queryParams?: any): Promise<any> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(constraintName, 'constraintName');
const pathParams = {
modelName,
constraintName
};
return this.get({
path: 'cmm/{modelName}/constraints{constraintName}',
pathParams,
queryParams
});
}
/**
* Delete the given custom model
*/
deleteCustomModel(modelName: string): Promise<void> {
throwIfNotDefined(modelName, 'modelName');
const pathParams = {
modelName
};
return this.delete({
path: 'cmm/{modelName}',
pathParams
});
}
/**
* Delete the given custom type
*/
deleteCustomType(modelName: string, typeName: string): Promise<void> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(typeName, 'typeName');
const pathParams = {
modelName,
typeName
};
return this.delete({
path: 'cmm/{modelName}/types/{typeName}',
pathParams
});
}
deleteCustomAspect(modelName: string, aspectName: string): Promise<void> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(aspectName, 'aspectName');
const pathParams = {
modelName,
aspectName
};
return this.delete({
path: 'cmm/{modelName}/aspects/{aspectName}',
pathParams
});
}
deleteCustomAspectProperty(modelName: string, aspectName: string, propertyName: string): Promise<{ entry: CustomAspect }> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(aspectName, 'aspectName');
throwIfNotDefined(propertyName, 'propertyName');
const bodyParam = {
name: aspectName
};
const pathParams = {
modelName,
aspectName
};
const queryParams = {
select: 'props',
delete: propertyName,
update: true
};
return this.put({
path: 'cmm/{modelName}/aspects/{aspectName}',
bodyParam,
pathParams,
queryParams
});
}
deleteCustomTypeProperty(modelName: string, typeName: string, propertyName: string): Promise<{ entry: CustomType }> {
throwIfNotDefined(modelName, 'modelName');
throwIfNotDefined(typeName, 'typeName');
throwIfNotDefined(propertyName, 'propertyName');
const bodyParam = {
name: typeName
};
const pathParams = {
modelName,
typeName
};
const queryParams = {
select: 'props',
delete: propertyName,
update: true
};
return this.put({
path: 'cmm/{modelName}/types/{typeName}',
bodyParam,
pathParams,
queryParams
});
}
}

View File

@@ -0,0 +1,22 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './webscript.api';
export * from './classes.api';
export * from './upload.api';
export * from './content.api';
export * from './customModel.api';

View File

@@ -0,0 +1,50 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { NodesApi } from '../../content-rest-api/api/nodes.api';
import { NodeBodyCreate, NodeEntry, CreateNodeOpts } from '../../content-rest-api';
export interface UploadFileOpts extends CreateNodeOpts {
name?: string;
renditions?: string;
}
export class UploadApi extends NodesApi {
uploadFile(fileDefinition: any, relativePath?: string, rootFolderId?: string, nodeBody?: NodeBodyCreate, opts?: UploadFileOpts): Promise<NodeEntry | any> {
rootFolderId = rootFolderId || '-root-';
opts = opts || {};
const nodeBodyRequired = {
name: fileDefinition.name,
nodeType: 'cm:content',
relativePath
};
nodeBody = Object.assign(nodeBodyRequired, nodeBody);
let formParam = Object.assign({}, nodeBody.properties || {});
formParam.filedata = fileDefinition;
formParam.relativePath = relativePath;
if (opts.name) {
formParam.name = opts.name;
}
formParam = Object.assign(formParam, opts);
return this.createNode(rootFolderId, nodeBody, opts, formParam);
}
}

View File

@@ -0,0 +1,76 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { BaseApi } from './base.api';
/**
* Constructs a new WebscriptApi.
*/
export class WebscriptApi extends BaseApi {
allowedMethod: string[] = ['GET', 'POST', 'PUT', 'DELETE'];
/**
* Call a get on a Web Scripts see https://wiki.alfresco.com/wiki/Web_Scripts for more details about Web Scripts
* Url syntax definition : http[s]://<host>:<port>/[<contextPath>/]/<servicePath>[/<scriptPath>][?<scriptArgs>]
* example: http://localhost:8081/share/service/mytasks?priority=1
*
* @param httpMethod GET, POST, PUT and DELETE
* @param scriptPath script path
* @param scriptArgs script arguments
* @param contextRoot default value alfresco
* @param servicePath default value service
* @param postBody post body
* @returns A promise that is resolved return the webScript data and {error} if rejected.
*/
executeWebScript(
httpMethod: string,
scriptPath: string,
scriptArgs?: any,
contextRoot?: string,
servicePath?: string,
postBody?: any
): Promise<any> {
contextRoot = contextRoot || 'alfresco';
servicePath = servicePath || 'service';
postBody = postBody || null;
if (!httpMethod || this.allowedMethod.indexOf(httpMethod) === -1) {
throw new Error('method allowed value GET, POST, PUT and DELETE');
}
if (!scriptPath) {
throw new Error('Missing param scriptPath in executeWebScript');
}
const contentTypes = ['application/json'];
const accepts = ['application/json', 'text/html'];
return this.apiClient.callApi(
'/' + servicePath + '/' + scriptPath,
httpMethod,
{},
scriptArgs,
{},
{},
postBody,
contentTypes,
accepts,
null,
contextRoot
);
}
}

View File

@@ -0,0 +1,31 @@
# UploadApi
| Method | Description |
|-------------------------------------------|---------------------|
| [**uploadFile**](UploadApi.md#uploadFile) | upload file content |
<a name="uploadFile"></a>
# **uploadFile**
> uploadFile(fileDefinition, relativePath: string, rootFolderId: string, nodeBody: any, opts?: any): Promise<NodeEntry | any>
**Example**
```javascript
const alfrescoApi = new AlfrescoApi(/*...*/);
const fs = require('fs');
const uploadApi = new UploadApi(alfrescoApi);
const fileToUpload = fs.createReadStream('./folderA/folderB/newFile.txt');
uploadApi.uploadFile(fileToUpload).then(
() => {
console.log('File Uploaded in the root');
},
(error) => {
console.log('Error during the upload' + error);
});
```

View File

@@ -0,0 +1,58 @@
# WebscriptApi
Method | HTTP request | Description
------------- | ------------- | -------------
[**executeWebScript**](WebscriptApi.md#executeWebScript) | | execute WebScript
<a name="executeWebScript"></a>
# **executeWebScript**
> executeWebScript(httpMethod, scriptPath, scriptArgs, contextRoot, servicePath)
For mor information about web scripts read the [Wiki](https://wiki.alfresco.com/wiki/Web_Scripts) and the [Wiki with Web ScriptsExamples](https://wiki.alfresco.com/wiki/Web_Scripts_Examples)
> Anatomy of a Web Script URI **http(s)://(host):(port)/(contextPath)/(servicePath)/(scriptPath)?(scriptArgs)**
A Web Script is simply a service bound to a URI which responds to HTTP methods such as GET, POST, PUT and DELETE. While using the same underlying code, there are broadly two kinds of Web Scripts.
### Parameters
Name | Type | Description | Notes|
------------- | ------------- | ------------- | -------------
**httpMethod** | **String**| possible value GET, POST, PUT and DELETE ||
**scriptPath** | **String**|path to Web Script (as defined by Web Script)||
**scriptArgs** | **String**|arguments to pass to Web Script ||
**contextRoot** | **String**|path where application is deployed default value 'alfresco'||
**servicePath** | **String**|path where Web Script service is mapped default value 'service'||
**postBody** | **Object**|post body||
### Example
```javascript
//Call a GET on a Web Scripts available at the following URIs: http://127.0.01:8080/alfresco/service/mytasks
this.alfrescoJsApi.core.webscriptApi.executeWebScript('GET', 'mytasks').then(function (data) {
console.log('Data received form http://127.0.01:8080/alfresco/service/mytasks' + data);
}, function (error) {
console.log('Error' + error);
});
//Call a GET on a Web Scripts available at the following URIs: http://127.0.01:8080/share/service/mytasks
this.alfrescoJsApi.core.webscriptApi.executeWebScript('GET', 'mytasks', null, 'share').then(function (data) {
console.log('Data received form http://127.0.01:8080/share/service/mytasks' + data);
}, function (error) {
console.log('Error' + error);
});
//Call a GET on a Web Scripts available at the following URIs: http://127.0.01:8080/share/differentServiceSlug/mytasks
this.alfrescoJsApi.core.webscriptApi.executeWebScript('GET', 'mytasks', null, 'share', 'differentServiceSlug').then(function (data) {
console.log('Data received form http://127.0.01:8080/share/differentServiceSlug/mytasks' + data);
}, function (error) {
console.log('Error' + error);
});
```

View File

@@ -0,0 +1,19 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './api';
export * from './model';

View File

@@ -0,0 +1,41 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ClassPropertyDescription } from './classPropertyDescription';
export class ClassDescription {
associations?: any;
childassociations?: any;
defaultAspects?: any;
description?: string;
isAspect?: boolean;
isContainer?: boolean;
name?: string;
parent?: any;
properties?: {
[key: string]: ClassPropertyDescription;
};
title?: string;
url?: string;
constructor(input?: Partial<ClassDescription>) {
if (input) {
Object.assign(this, input);
}
}
}

View File

@@ -0,0 +1,37 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export class ClassPropertyDescription {
dataType?: string;
defaultValue?: string;
description?: string;
enforced?: boolean;
indexed?: boolean;
mandatory?: boolean;
multiValued?: boolean;
name?: string;
protected?: boolean;
title?: string;
url?: string;
constructor(input?: Partial<ClassPropertyDescription>) {
if (input) {
Object.assign(this, input);
}
}
}

View File

@@ -0,0 +1,83 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export class DateAlfresco extends Date {
/**
* Parses an ISO-8601 string representation of a date value.
*
* @param dateToConvert The date value as a string.
* @returns The parsed date object.
*/
static parseDate(dateToConvert: any): Date {
if (dateToConvert instanceof Date) {
return dateToConvert;
} else if (typeof dateToConvert === 'number') {
return new Date(dateToConvert);
}
const dateLength = 10;
const separatorPos = dateToConvert.substring(dateLength).search(/[+-]/) + dateLength;
const dateStr = separatorPos > dateLength ? dateToConvert.substring(0, separatorPos) : dateToConvert;
const tzStr = separatorPos > dateLength ? dateToConvert.substring(separatorPos) : '';
const parsedDate = this.parseDateTime(dateStr);
const tzOffsetMins = this.parseDateTimeZone(tzStr);
parsedDate.setTime(parsedDate.getTime() + tzOffsetMins * 60000);
return parsedDate;
}
/**
* Parses the date component of a ISO-8601 string representation of a date value.
*
* @param dateToConvert The date value as a string.
* @returns The parsed date object.
*/
static parseDateTime(dateToConvert: string): Date {
// TODO: review when Safari 10 is released
// return new Date(str.replace(/T/i, ' '));
// Compatible with Safari 9.1.2
const dateParts = dateToConvert.split(/[^0-9]/).map(function(s) {
return parseInt(s, 10);
});
return new Date(
Date.UTC(
dateParts[0],
dateParts[1] - 1 || 0,
dateParts[2] || 1,
dateParts[3] || 0,
dateParts[4] || 0,
dateParts[5] || 0,
dateParts[6] || 0
)
);
}
/**
* Parses the timezone component of a ISO-8601 string representation of a date value.
*
* @param dateToConvert The timezone offset as a string, e.g. '+0000', '+2000' or '-0500'.
* @returns The number of minutes offset from UTC.
*/
static parseDateTimeZone(dateToConvert: string): number {
const match = /([+-])(\d{2}):?(\d{2})?/.exec(dateToConvert);
if (match !== null) {
return parseInt(match[1] + '1', 10) * -1 * (parseInt(match[2], 10) * 60) + parseInt(match[3] || '0', 10);
} else {
return 0;
}
}
}

View File

@@ -0,0 +1,21 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './dateAlfresco';
export * from './classDescription';
export * from './classPropertyDescription';
export * from './pagination';

View File

@@ -0,0 +1,30 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Pagination } from '../../content-rest-api/model/pagination';
export interface PaginatedList<T> {
list: {
entries: Array<{ entry: T }>;
pagination: Pagination;
};
}
export interface PaginatedEntries<T> {
entries: T[];
pagination: Pagination;
}