Skip to content

Commit

Permalink
Cloud API updates (#32)
Browse files Browse the repository at this point in the history
* Cloud API updates

* e2e tests fixes

* prettier
  • Loading branch information
MrRefactoring authored Sep 12, 2022
1 parent ac097f5 commit a0a29aa
Show file tree
Hide file tree
Showing 37 changed files with 961 additions and 86 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

### 1.6.0

Cloud API:
- `asyncConvertContentBodyRequest` method added to `ContentBody` API.
- `asyncConvertContentBodyResponse` method added to `ContentBody` API.
- [`ContentContentState`](https://github.com/MrRefactoring/confluence.js/blob/master/src/api/contentContentState.ts) API are deprecated. Use [`ContentStates`](https://github.com/MrRefactoring/confluence.js/blob/master/src/api/contentStates.ts) instead.
- `getAndConvertMacroBodyByMacroId` method added to `ContentMacroBody` API.
- `getAndAsyncConvertMacroBodyByMacroId` method added to `ContentMacroBody` API.
- `registerModules` method fixed via adding body to the request. `DynamicModules` API.
- Other fixes and improvements. (like `expand` property adding).

### 1.5.3

`expand` property added to `convertContentBody` method to `ContentBody` API. Thanks to [Federico Gonzalez](https://github.com/FedeG) for report.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ Available groups:
- [contentPermissions](https://developer.atlassian.com/cloud/confluence/rest/api-group-content-permissions/#api-group-content-permissions)
- [contentProperties](https://developer.atlassian.com/cloud/confluence/rest/api-group-content-properties/#api-group-content-properties)
- [contentRestrictions](https://developer.atlassian.com/cloud/confluence/rest/api-group-content-restrictions/#api-group-content-restrictions)
- [contentStates](https://developer.atlassian.com/cloud/confluence/rest/api-group-content-states/#api-group-content-states)
- [contentVersions](https://developer.atlassian.com/cloud/confluence/rest/api-group-content-versions/#api-group-content-versions)
- [contentWatches](https://developer.atlassian.com/cloud/confluence/rest/api-group-content-watches/#api-group-content-watches)
- [dynamicModules](https://developer.atlassian.com/cloud/confluence/rest/api-group-dynamic-modules/#api-group-dynamic-modules)
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "confluence.js",
"version": "1.5.3",
"version": "1.6.0",
"description": "confluence.js is a powerful Node.JS/Browser module that allows you to interact with the Confluence API very easily",
"author": "Vladislav Tupikin <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -60,7 +60,7 @@
"sinon": "^14.0.0",
"typedoc": "^0.23.14",
"typedoc-plugin-extras": "^2.3.0",
"typescript": "^4.8.2"
"typescript": "^4.8.3"
},
"dependencies": {
"atlassian-jwt": "^2.0.2",
Expand Down
100 changes: 100 additions & 0 deletions src/api/contentBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,104 @@ export class ContentBody {

return this.client.sendRequest(config, callback);
}

/**
* Converts a content body from one format to another format asynchronously. Returns the asyncId for the asynchronous
* task.
*
* Supported conversions:
*
* - Storage: export_view
*
* No other conversions are supported at the moment. Once a conversion is completed, it will be available for 5
* minutes at the result endpoint.
*
* **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: If request specifies 'contentIdContext',
* 'View' permission for the space, and permission to view the content.
*/
async asyncConvertContentBodyRequest<T = Models.AsyncId>(
parameters: Parameters.AsyncConvertContentBodyRequest,
callback: Callback<T>
): Promise<void>;
/**
* Converts a content body from one format to another format asynchronously. Returns the asyncId for the asynchronous
* task.
*
* Supported conversions:
*
* - Storage: export_view
*
* No other conversions are supported at the moment. Once a conversion is completed, it will be available for 5
* minutes at the result endpoint.
*
* **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: If request specifies 'contentIdContext',
* 'View' permission for the space, and permission to view the content.
*/
async asyncConvertContentBodyRequest<T = Models.AsyncId>(
parameters: Parameters.AsyncConvertContentBodyRequest,
callback?: never
): Promise<T>;
async asyncConvertContentBodyRequest<T = Models.AsyncId>(
parameters: Parameters.AsyncConvertContentBodyRequest,
callback?: Callback<T>,
): Promise<void | T> {
const config: RequestConfig = {
url: `/api/contentbody/convert/async/${parameters.to}`,
method: 'POST',
params: {
spaceKeyContext: parameters.spaceKeyContext,
contentIdContext: parameters.contentIdContext,
allowCache: parameters.allowCache,
embeddedContentRender: parameters.embeddedContentRender,
expand: parameters.expand,
},
data: {
value: parameters.value,
representation: parameters.representation,
...parameters.additionalProperties,
},
};

return this.client.sendRequest(config, callback);
}

/**
* Returns the Asynchronous Content Body for the corresponding asyncId if the task is complete or returns the status
* of the task.
*
* After the task is completed, the result can be obtained for 5 minutes, or until an identical conversion request is
* made again, with allowCache query param set to false.
*
* **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: If request specifies 'contentIdContext',
* 'View' permission for the space, and permission to view the content.
*/
async asyncConvertContentBodyResponse<T = Models.AsyncContentBody>(
parameters: Parameters.AsyncConvertContentBodyResponse,
callback: Callback<T>
): Promise<void>;
/**
* Returns the Asynchronous Content Body for the corresponding asyncId if the task is complete or returns the status
* of the task.
*
* After the task is completed, the result can be obtained for 5 minutes, or until an identical conversion request is
* made again, with allowCache query param set to false.
*
* **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: If request specifies 'contentIdContext',
* 'View' permission for the space, and permission to view the content.
*/
async asyncConvertContentBodyResponse<T = Models.AsyncContentBody>(
parameters: Parameters.AsyncConvertContentBodyResponse,
callback?: never
): Promise<T>;
async asyncConvertContentBodyResponse<T = Models.AsyncContentBody>(
parameters: Parameters.AsyncConvertContentBodyResponse,
callback?: Callback<T>,
): Promise<void | T> {
const config: RequestConfig = {
url: `/api/contentbody/convert/async/${parameters.id}`,
method: 'GET',
};

return this.client.sendRequest(config, callback);
}
}
4 changes: 3 additions & 1 deletion src/api/contentChildrenAndDescendants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ export class ContentChildrenAndDescendants {
*/
async movePage<T = Models.MovePage>(parameters: Parameters.MovePage, callback?: never): Promise<T>;
async movePage<T = Models.MovePage>(parameters: Parameters.MovePage, callback?: Callback<T>): Promise<void | T> {
const pageId = parameters.pageId || parameters.id;

const config: RequestConfig = {
url: `/api/content/${parameters.id}/move/${parameters.position}/${parameters.targetId}`,
url: `/api/content/${pageId}/move/${parameters.position}/${parameters.targetId}`,
method: 'PUT',
};

Expand Down
58 changes: 30 additions & 28 deletions src/api/contentContentState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ import { Callback } from '../callback';
import { Client } from '../clients';
import { RequestConfig } from '../requestConfig';

/** @deprecated Use {@link ContentStates} instead. */
export class ContentContentState {
/** @deprecated */
constructor(private client: Client) {}

/**
* Gets the current page status of the draft or published version of content. To specify the draft version, set the
* parameter status to PUBLISHED, otherwise DRAFT.
* @deprecated Gets the current page status of the draft or published version of content. To specify the draft
* version, set the parameter status to PUBLISHED, otherwise DRAFT.
*/
async getContentState<T = Models.ContentStateContainer>(
parameters: Parameters.GetContentState,
callback: Callback<T>
): Promise<void>;
/**
* Gets the current page status of the draft or published version of content. To specify the draft version, set the
* parameter status to PUBLISHED, otherwise DRAFT.
* @deprecated Gets the current page status of the draft or published version of content. To specify the draft
* version, set the parameter status to PUBLISHED, otherwise DRAFT.
*/
async getContentState<T = Models.ContentStateContainer>(
parameters: Parameters.GetContentState,
Expand All @@ -39,28 +41,28 @@ export class ContentContentState {
}

/**
* Sets the content state of the content specified and creates a new version (publishes the content without changing
* the body) of the content with the new status. The desired type of status must be allowed. There are space suggested
* statuses and custom statuses. To specify the desired new status, one can use the id of the status or the name and
* color of the status. If contentStateId is defined, then name and color are ignored. If contentStateId is not
* defined, name and color will be used if provided. Firstly, we will determine if a status of this name and color
* exists, and if it does, that this status is used. If it does not exist, and custom statuses are allowed, a custom
* status with this name and color will be created. Color can be specified in traditional english colors (teal,
* magenta, lavender, etc.) or as a hex string ex: #0ff0Fd.
* @deprecated Sets the content state of the content specified and creates a new version (publishes the content
* without changing the body) of the content with the new status. The desired type of status must be allowed. There
* are space suggested statuses and custom statuses. To specify the desired new status, one can use the id of the
* status or the name and color of the status. If contentStateId is defined, then name and color are ignored. If
* contentStateId is not defined, name and color will be used if provided. Firstly, we will determine if a status of
* this name and color exists, and if it does, that this status is used. If it does not exist, and custom statuses
* are allowed, a custom status with this name and color will be created. Color can be specified in traditional
* english colors (teal, magenta, lavender, etc.) or as a hex string ex: #0ff0Fd.
*/
async setContentState<T = Models.ContentStateContainer>(
parameters: Parameters.SetContentState,
callback: Callback<T>
): Promise<void>;
/**
* Sets the content state of the content specified and creates a new version (publishes the content without changing
* the body) of the content with the new status. The desired type of status must be allowed. There are space suggested
* statuses and custom statuses. To specify the desired new status, one can use the id of the status or the name and
* color of the status. If contentStateId is defined, then name and color are ignored. If contentStateId is not
* defined, name and color will be used if provided. Firstly, we will determine if a status of this name and color
* exists, and if it does, that this status is used. If it does not exist, and custom statuses are allowed, a custom
* status with this name and color will be created. Color can be specified in traditional english colors (teal,
* magenta, lavender, etc.) or as a hex string ex: #0ff0Fd.
* @deprecated Sets the content state of the content specified and creates a new version (publishes the content
* without changing the body) of the content with the new status. The desired type of status must be allowed. There
* are space suggested statuses and custom statuses. To specify the desired new status, one can use the id of the
* status or the name and color of the status. If contentStateId is defined, then name and color are ignored. If
* contentStateId is not defined, name and color will be used if provided. Firstly, we will determine if a status of
* this name and color exists, and if it does, that this status is used. If it does not exist, and custom statuses
* are allowed, a custom status with this name and color will be created. Color can be specified in traditional
* english colors (teal, magenta, lavender, etc.) or as a hex string ex: #0ff0Fd.
*/
async setContentState<T = Models.ContentStateContainer>(
parameters: Parameters.SetContentState,
Expand All @@ -84,16 +86,16 @@ export class ContentContentState {
}

/**
* Removes the content state of the content specified and creates a new version (publishes the content without
* changing the body) of the content with the new status.
* @deprecated Removes the content state of the content specified and creates a new version (publishes the content
* without changing the body) of the content with the new status.
*/
async removeContentState<T = Models.ContentStateContainer>(
parameters: Parameters.RemoveContentState,
callback: Callback<T>
): Promise<void>;
/**
* Removes the content state of the content specified and creates a new version (publishes the content without
* changing the body) of the content with the new status.
* @deprecated Removes the content state of the content specified and creates a new version (publishes the content
* without changing the body) of the content with the new status.
*/
async removeContentState<T = Models.ContentStateContainer>(
parameters: Parameters.RemoveContentState,
Expand All @@ -111,12 +113,12 @@ export class ContentContentState {
return this.client.sendRequest(config, callback);
}

/** Gets a Global Timestamp of the last time the content state was updated */
/** @deprecated Gets a Global Timestamp of the last time the content state was updated */
async getContentStateLastUpdated<T = unknown>(
parameters: Parameters.GetContentStateLastUpdated,
callback: Callback<T>
): Promise<void>;
/** Gets a Global Timestamp of the last time the content state was updated */
/** @deprecated Gets a Global Timestamp of the last time the content state was updated */
async getContentStateLastUpdated<T = unknown>(
parameters: Parameters.GetContentStateLastUpdated,
callback?: never
Expand All @@ -133,12 +135,12 @@ export class ContentContentState {
return this.client.sendRequest(config, callback);
}

/** Gets content states that are available for the content to be set as. */
/** @deprecated Gets content states that are available for the content to be set as. */
async getAvailableContentStates<T = Models.AvailableContentStates>(
parameters: Parameters.GetAvailableContentStates,
callback: Callback<T>
): Promise<void>;
/** Gets content states that are available for the content to be set as. */
/** @deprecated Gets content states that are available for the content to be set as. */
async getAvailableContentStates<T = Models.AvailableContentStates>(
parameters: Parameters.GetAvailableContentStates,
callback?: never
Expand Down
Loading

0 comments on commit a0a29aa

Please sign in to comment.