From 988d99ae472ebb57f7562814d2909bd4a2c8fb6c Mon Sep 17 00:00:00 2001 From: Peter Crackenberg Date: Fri, 2 Jun 2023 14:42:12 -0700 Subject: [PATCH 01/10] Added functionality and documentation for folder wrapper functions. --- cascade.js | 68 +++++++++++++++++++++- documentation/cascade-api.md | 97 ++++++++++++++++++++++++++++++- documentation/folder-functions.md | 88 ++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+), 2 deletions(-) create mode 100644 documentation/folder-functions.md diff --git a/cascade.js b/cascade.js index 28ee19f..ea3a60b 100644 --- a/cascade.js +++ b/cascade.js @@ -78,6 +78,15 @@ class Cascade return new CascadeAsset("file"); } + /** + * Return a blank folder, this is helpful when creating new assets. + * @returns {CascadeAsset} Blank folder + */ + createBlankFolder() + { + return new CascadeAsset("folder"); + } + /**** API Functions ****/ /** @@ -182,6 +191,17 @@ class Cascade return await this.APICall("read","file",path); } + /** + * Read a folder, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + * @param {string} path Path or ID of folder to read + * @returns {Object} Object representing the Cascade response. Page that was found will be in the .asset.page attribute + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async readFolder(path) + { + return await this.APICall("read","folder",path); + } + /** * Delete a page, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. * @param {string} path Path or ID of page to delete @@ -204,6 +224,17 @@ class Cascade return await this.APICall("delete","file",path); } + /** + * Delete a folder, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + * @param {string} path Path or ID of folder to delete + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async deleteFolder(path) + { + return await this.APICall("delete","folder",path); + } + /** * Edit a page, given a Cascade page object. Typically the page to edit is read in via [readPage]{@link Cascade#readPage}, * but it can be manually created as well. @@ -228,6 +259,18 @@ class Cascade return await this.APICall("edit","file",assetObject.path,{file: assetObject}); } + /** + * Edit a folder, given a Cascade folder object. Typically the page to edit is read in via [readFolder]{@link Cascade#readFolder}, + * but it can be manually created as well. + * @param {Object} assetObject Cascade object representing the folder. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async editFolder(assetObject) + { + return await this.APICall("edit","folder",assetObject.path,{folder: assetObject}); + } + /** * Publish a page, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. * @param {string} path Path or ID of page to publish. @@ -250,6 +293,17 @@ class Cascade return await this.APICall("publish","file",path); } + /** + * Publish a folder, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + * @param {string} path Path or ID of folder to publish. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async publishFolder(path) + { + return await this.APICall("publish","folder",path); + } + /** * Create a page, given a Cascade page object. Typically this is created using [createBlankPage]{@link Cascade#createBlankPage}, * but it can be created manually as well. @@ -263,7 +317,7 @@ class Cascade } /** - * Create a file, given a Cascade file object. Typically this is created using [createBlanFile]{@link Cascade#createBlankFile}, + * Create a file, given a Cascade file object. Typically this is created using [createBlankFile]{@link Cascade#createBlankFile}, * but it can be created manually as well. * @param {Object} assetObject Cascade object representing the file. * @returns {Object} Object representing the Cascade response. @@ -274,6 +328,18 @@ class Cascade return await this.APICall("create",false,false,{file: assetObject}); } + /** + * Create a folder, given a Cascade folder object. Typically this is created using [createBlankFolder]{@link Cascade#createBlankFolder}, + * but it can be created manually as well. + * @param {Object} assetObject Cascade object representing the folder. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async createFolder(assetObject) + { + return await this.APICall("create",false,false,{folder: assetObject}); + } + } /** diff --git a/documentation/cascade-api.md b/documentation/cascade-api.md index 28f40e9..a28bb32 100644 --- a/documentation/cascade-api.md +++ b/documentation/cascade-api.md @@ -36,17 +36,23 @@ Otherwise it will use a Cascade asset ID. You can swap modes using the [useId](# * [.useId()](#Cascade+useId) * [.createBlankPage()](#Cascade+createBlankPage) ⇒ [CascadeAsset](#CascadeAsset) * [.createBlankFile()](#Cascade+createBlankFile) ⇒ [CascadeAsset](#CascadeAsset) + * [.createBlankFolder()](#Cascade+createBlankFolder) ⇒ [CascadeAsset](#CascadeAsset) * [.APICall(operation, [type], [assetIDPath], [assetObject])](#Cascade+APICall) ⇒ Object * [.readPage(path)](#Cascade+readPage) ⇒ Object * [.readFile(path)](#Cascade+readFile) ⇒ Object + * [.readFolder(path)](#Cascade+readFolder) ⇒ Object * [.deletePage(path)](#Cascade+deletePage) ⇒ Object * [.deleteFile(path)](#Cascade+deleteFile) ⇒ Object + * [.deleteFolder(path)](#Cascade+deleteFolder) ⇒ Object * [.editPage(assetObject)](#Cascade+editPage) ⇒ Object * [.editFile(assetObject)](#Cascade+editFile) ⇒ Object + * [.editFolder(assetObject)](#Cascade+editFolder) ⇒ Object * [.publishPage(path)](#Cascade+publishPage) ⇒ Object * [.publishFile(path)](#Cascade+publishFile) ⇒ Object + * [.publishFolder(path)](#Cascade+publishFolder) ⇒ Object * [.createPage(assetObject)](#Cascade+createPage) ⇒ Object * [.createFile(assetObject)](#Cascade+createFile) ⇒ Object + * [.createFolder(assetObject)](#Cascade+createFolder) ⇒ Object @@ -96,6 +102,13 @@ Return a blank file, this is helpful when creating new assets. **Kind**: instance method of [Cascade](#Cascade) **Returns**: [CascadeAsset](#CascadeAsset) - Blank file + + +### cascade.createBlankFolder() ⇒ [CascadeAsset](#CascadeAsset) +Return a blank folder, this is helpful when creating new assets. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: [CascadeAsset](#CascadeAsset) - Blank folder ### cascade.APICall(operation, [type], [assetIDPath], [assetObject]) ⇒ Object @@ -152,6 +165,22 @@ Read a file, given a path or ID (depending on the mode of the Cascade object) an | --- | --- | --- | | path | string | Path or ID of file to read | + + +### cascade.readFolder(path) ⇒ Object +Read a folder, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. Page that was found will be in the .asset.page attribute +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of folder to read | + ### cascade.deletePage(path) ⇒ Object @@ -184,6 +213,22 @@ Delete a file, given a path or ID (depending on the mode of the Cascade object) | --- | --- | --- | | path | string | Path or ID of file to delete | + + +### cascade.deleteFolder(path) ⇒ Object +Delete a folder, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of folder to delete | + ### cascade.editPage(assetObject) ⇒ Object @@ -218,6 +263,23 @@ but it can be manually created as well. | --- | --- | --- | | assetObject | Object | Cascade object representing the file. | + + +### cascade.editFolder(assetObject) ⇒ Object +Edit a folder, given a Cascade folder object. Typically the page to edit is read in via [readFolder](#Cascade+readFolder), +but it can be manually created as well. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| assetObject | Object | Cascade object representing the folder. | + ### cascade.publishPage(path) ⇒ Object @@ -250,6 +312,22 @@ Publish a file, given a path or ID (depending on the mode of the Cascade object) | --- | --- | --- | | path | string | Path or ID of file to publish. | + + +### cascade.publishFolder(path) ⇒ Object +Publish a folder, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of folder to publish. | + ### cascade.createPage(assetObject) ⇒ Object @@ -270,7 +348,7 @@ but it can be created manually as well. ### cascade.createFile(assetObject) ⇒ Object -Create a file, given a Cascade file object. Typically this is created using [createBlanFile](#Cascade+createBlankFile), +Create a file, given a Cascade file object. Typically this is created using [createBlankFile](#Cascade+createBlankFile), but it can be created manually as well. **Kind**: instance method of [Cascade](#Cascade) @@ -284,6 +362,23 @@ but it can be created manually as well. | --- | --- | --- | | assetObject | Object | Cascade object representing the file. | + + +### cascade.createFolder(assetObject) ⇒ Object +Create a folder, given a Cascade folder object. Typically this is created using [createBlankFolder](#Cascade+createBlankFolder), +but it can be created manually as well. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| assetObject | Object | Cascade object representing the folder. | + ## CascadeAsset diff --git a/documentation/folder-functions.md b/documentation/folder-functions.md new file mode 100644 index 0000000..cf90bec --- /dev/null +++ b/documentation/folder-functions.md @@ -0,0 +1,88 @@ +# Folder Functions + +## Read Folder + +```javascript +cascadeAPI.readFolder("/test") +.then(response=>{ + console.log("Success reading folder:"); + console.log(response); +}) +.catch(error=>{ + console.error("Erroring reading folder:"); + console.error(error); +}); +``` + +## Edit Folder + +```javascript +cascadeAPI.readFolder("/test/test2") +.then(response=>{ + console.log("Success reading folder:"); + const foundFolder = response.asset.folder; + foundFolder.metadata.displayName = "New Display Name"; + cascadeAPI.editFolder(foundFolder) + .then(response=>{ + console.log("Success editing folder:"); + console.log(response); + }) + .catch(error => { + console.errer("Error editing folder:"); + console.errer(error); + }); +}) +.catch(error=>{ + console.error("Error reading folder:"); + console.error(error); +}); +``` + +## Create Folder +The same as creating a new page, an asset must be sent when creating a new folder. There is a `createBlankFolder()` helper function for this as well. Unlike a page the only things that are required are `siteName`, `parentFolderPath` and `name`. + +The asset ID of the newly created folder will be returned on success. +```javascript +const newFolder = cascadeAPI.createBlankFolder(); +newFolder.siteName = cascadeAPI.site; +newFolder.parentFolderPath = "/test"; +newFolder.name = "test2"; +console.log(newFolder); +cascadeAPI.createFolder(newFolder) +.then(response=>{ + console.log("Success creating folder:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error creating folder:"); + console.error(error); +}); +``` + +## Delete Folder + +```javascript +cascadeAPI.deleteFolder("/test/test2") +.then(response=>{ + console.log("Success deleting folder:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error deleting folder:"); + console.error(error); +}); +``` + +## Publish Folder + +```javascript +cascadeAPI.publishFolder("/test/test2") +.then(response=>{ + console.log("Success publishing folder:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error publishing folder:"); + console.error(error); +}); +``` \ No newline at end of file From e5110f36c06df35758edeb552b7dc6bd1d0c576a Mon Sep 17 00:00:00 2001 From: Peter Crackenberg Date: Fri, 2 Jun 2023 15:00:54 -0700 Subject: [PATCH 02/10] Cleaned up a couple of references to the new folder functions that got missed in comments and documentation. --- README.md | 1 + cascade.js | 10 +++++----- documentation/cascade-api.md | 18 +++++++++--------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 96565a6..e3e24f0 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ Examples will use the variable `cascadeAPI` from above. These examples use paths * [Page Functions](documentation/page-functions.md) * [File Functions](documentation/file-functions.md) +* [Folder Functions](documentation/folder-functions.md) * [Other API Uses](documentation/other-api.md) ## Full Documentation diff --git a/cascade.js b/cascade.js index ea3a60b..c27fdba 100644 --- a/cascade.js +++ b/cascade.js @@ -347,17 +347,17 @@ class Cascade * when creating a new asset, as it makes it easier than creating the required * properties from scratch. * - * Typically used to create new objects when using the [createPage]{@link Cascade#createPage} and - * [createFile]{@link Cascade#createFile} functions. + * Typically used to create new objects when using the [createPage]{@link Cascade#createPage}, + * [createFile]{@link Cascade#createFile}, and [createFolder]{@link Cascade#createFolder} functions. * - * These are returned by the [createBlankPage]{@link Cascade#createBlankPage} and - * [createBlankFile]{@link Cascade#createBlankFile} methods. + * These are returned by the [createBlankPage]{@link Cascade#createBlankPage}, + * [createBlankFile]{@link Cascade#createBlankFile}, and [createBlankFolder]{@link Cascade#createBlankFolder} methods. */ class CascadeAsset { /** * Create a new CascadeAsset object. - * @param {string} [type=page] Either page or file, defaults to page. + * @param {string} [type=page] Either page, file, or folder. Defaults to page. */ constructor(type="page") { diff --git a/documentation/cascade-api.md b/documentation/cascade-api.md index a28bb32..fa3ebd6 100644 --- a/documentation/cascade-api.md +++ b/documentation/cascade-api.md @@ -12,10 +12,10 @@ Otherwise it will use a Cascade asset ID. You can swap modes using the createPage and -createFile functions.

-

These are returned by the createBlankPage and -createBlankFile methods.

+

Typically used to create new objects when using the createPage, +createFile, and createFolder functions.

+

These are returned by the createBlankPage, +createBlankFile, and createBlankFolder methods.

@@ -386,11 +386,11 @@ Class to represent assets to submit into Cascade Server. These are generally use when creating a new asset, as it makes it easier than creating the required properties from scratch. -Typically used to create new objects when using the [createPage](#Cascade+createPage) and -[createFile](#Cascade+createFile) functions. +Typically used to create new objects when using the [createPage](#Cascade+createPage), +[createFile](#Cascade+createFile), and [createFolder](#Cascade+createFolder) functions. -These are returned by the [createBlankPage](#Cascade+createBlankPage) and -[createBlankFile](#Cascade+createBlankFile) methods. +These are returned by the [createBlankPage](#Cascade+createBlankPage), +[createBlankFile](#Cascade+createBlankFile), and [createBlankFolder](#Cascade+createBlankFolder) methods. **Kind**: global class @@ -401,5 +401,5 @@ Create a new CascadeAsset object. | Param | Type | Default | Description | | --- | --- | --- | --- | -| [type] | string | "page" | Either page or file, defaults to page. | +| [type] | string | "page" | Either page, file, or folder. Defaults to page. | From 44588408961c9f349ed6c3f0fde02a3be857e7d2 Mon Sep 17 00:00:00 2001 From: Peter Crackenberg Date: Fri, 30 Jun 2023 16:13:26 -0700 Subject: [PATCH 03/10] Adding new wrapper functions for several types, and added a new ajaxparameters param to the APICall function. --- cascade.js | 126 +++++++++++++++++++++++++++++- documentation/file-functions.md | 14 ++++ documentation/folder-functions.md | 14 ++++ documentation/other-api.md | 4 +- documentation/page-functions.md | 14 ++++ 5 files changed, 169 insertions(+), 3 deletions(-) diff --git a/cascade.js b/cascade.js index c27fdba..296f05c 100644 --- a/cascade.js +++ b/cascade.js @@ -101,10 +101,11 @@ class Cascade * @param {string} [type=false] Optional. Required for calls where an identifier is needed (read, publish, etc). If not needed use default. * @param {string} [assetIDPath=false] Optional. Either the path or id of the asset, needed where an identifier is needed, like type. If not needed use default. * @param {Object} [assetObject=false] Optional. Asset to be acted upon, needed for some calls (create, edit). Must have an attribute for the asset type that's being acted upon (page, block, etc) + * @param {Object} [ajaxParameters=false] Optional. Parameters to be added to the body, examples being copyParameters or moveParameters which are required for those operations. * @returns {Object} Cascade response object. It could be either a system response for an operation like create or edit, or an object for an operation like read. * @throws Will throw an error if the Cascade API operation was not successful. */ - async APICall(operation,type=false,assetIDPath=false,assetObject=false) + async APICall(operation,type=false,assetIDPath=false,assetObject=false,ajaxParameters=false) { // Build the url to call this.ajaxURL = this.apiRoot+"/api/v1/"+operation; @@ -149,6 +150,12 @@ class Cascade this.ajaxOptions.body.asset = assetObject; } + // CHeck to see if there are additional parameters that need to be added to the body, and add them if needed. + if(typeof ajaxParameters === "object") + { + this.ajaxOptions.body = { ...this.ajaxOptions.body, ...ajaxParameters } + } + // Turn the body message into a JSON string to send it along this.ajaxOptions.body = JSON.stringify(this.ajaxOptions.body); @@ -340,6 +347,123 @@ class Cascade return await this.APICall("create",false,false,{folder: assetObject}); } + async movePage(path,newName,folderPath) + { + return await this.doMove(path,newName,folderPath, "page"); + } + + async moveFile(path,newName,folderPath) + { + return await this.doMove(path,newName,folderPath, "file"); + } + + async moveFolder(path,newName,folderPath) + { + return await this.doMove(path,newName,folderPath, "folder"); + } + + async doMove(path,newName,folderPath, type) + { + const moveParameters = { + "destinationContainerIdentifier": { + "type": "folder" + }, + "doWorkflow": "false", + "newName": newName + }; + + if(folderPath.hasOwnProperty("path") && !folderPath.hasOwnProperty("siteName") && this.identificationMode === "path") + { + folderPath.siteName = this.site; + } + + if(folderPath.hasOwnProperty("path")) + { + moveParameters.destinationContainerIdentifier.path = folderPath; + } + else if(folderPath.hasOwnProperty("id")) + { + moveParameters.destinationContainerIdentifier.id = folderPath.id; + } + + return await this.APICall("move", type, path, false, {"moveParameters": moveParameters}); + } + + async copyPage(path,newName,folderPath) + { + return await this.makeCopy(path,newName,folderPath,"page"); + } + + async copyFile(path,newName,folderPath) + { + return await this.makeCopy(path,newName,folderPath,"file"); + } + + async copyFolder(path,newName,folderPath) + { + return await this.makeCopy(path,newName,folderPath,"folder"); + } + + async makeCopy(path,newName,folderPath, type) + { + const copyParameters = { + "destinationContainerIdentifier": { + "type": "folder" + }, + "doWorkflow": "false", + "newName": newName + }; + + if(folderPath.hasOwnProperty("path") && !folderPath.hasOwnProperty("siteName") && this.identificationMode === "path") + { + folderPath.siteName = this.site; + } + + if(folderPath.hasOwnProperty("path")) + { + copyParameters.destinationContainerIdentifier.path = folderPath; + } + else if(folderPath.hasOwnProperty("id")) + { + copyParameters.destinationContainerIdentifier.id = folderPath.id; + } + + return await this.APICall("copy", type, path, false, {"copyParameters": copyParameters}); + } + + /** + * Check relationships for a page, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + * @param {string} path Path or ID of page to check. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async checkRelationshipsPage(path) + { + return await this.APICall("listSubscribers","page",path); + } + + /** + * Check relationships for a file, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + * @param {string} path Path or ID of file to check. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async checkRelationshipsFile(path) + { + return await this.APICall("listSubscribers","file",path); + } + + /** + * Check relationships for a folder, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + * @param {string} path Path or ID of folder to check. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async checkRelationshipsFolder(path) + { + return await this.APICall("listSubscribers","folder",path); + } + } /** diff --git a/documentation/file-functions.md b/documentation/file-functions.md index 5a42159..b8b544f 100644 --- a/documentation/file-functions.md +++ b/documentation/file-functions.md @@ -121,4 +121,18 @@ cascadeAPI.publishFile("/test/test.txt") console.log("Error publishing file:"); console.log(error); }); +``` + +## Check File Relationships + +```javascript +cascadeAPI.checkRelationshipsFile("/test/image.jpg") +.then(response=>{ + console.log("Success getting relationships:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error getting relationships:"); + console.error(error); +}); ``` \ No newline at end of file diff --git a/documentation/folder-functions.md b/documentation/folder-functions.md index cf90bec..25f231c 100644 --- a/documentation/folder-functions.md +++ b/documentation/folder-functions.md @@ -85,4 +85,18 @@ cascadeAPI.publishFolder("/test/test2") console.error("Error publishing folder:"); console.error(error); }); +``` + +## Check Folder Relationships + +```javascript +cascadeAPI.checkRelationshipsFolder("/test") +.then(response=>{ + console.log("Success getting relationships:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error getting relationships:"); + console.error(error); +}); ``` \ No newline at end of file diff --git a/documentation/other-api.md b/documentation/other-api.md index 526490d..9493e1a 100644 --- a/documentation/other-api.md +++ b/documentation/other-api.md @@ -1,9 +1,9 @@ # Other API Uses -If an operation isn't specified, you can call the `APICall` function directly to access it. This one lists subscribers for a page: +If an operation doesn't have a wrapper function listed for it, you can call the `APICall` function directly to access it. This one reads access rights for a page: ```javascript -cascadeAPI.APICall("listSubscribers","page","/test/test") +cascadeAPI.APICall("readAccessRights","page","/test/test") .then(response=>{ console.log("Call succeeded"); console.log(response); diff --git a/documentation/page-functions.md b/documentation/page-functions.md index 4b48d86..aeae0ca 100644 --- a/documentation/page-functions.md +++ b/documentation/page-functions.md @@ -88,4 +88,18 @@ cascadeAPI.publishPage("/test/test") console.log("Error publishing page:"); console.log(error); }); +``` + +## Check Page Relationships + +```javascript +cascadeAPI.checkRelationshipsPage("/test/test") +.then(response=>{ + console.log("Success getting relationships:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error getting relationships:"); + console.error(error); +}); ``` \ No newline at end of file From 53448c5f49914a3eead43b9ee56aa7494d99246a Mon Sep 17 00:00:00 2001 From: Peter Crackenberg Date: Fri, 28 Jul 2023 15:27:54 -0700 Subject: [PATCH 04/10] Added documentation for new functions, and a few test functions in the test file. --- cascade.js | 79 +++++++++++++ documentation/cascade-api.md | 219 ++++++++++++++++++++++++++++++++++- test-cascade-api.js | 200 +++++++++++++++++++++++++++++++- 3 files changed, 494 insertions(+), 4 deletions(-) diff --git a/cascade.js b/cascade.js index 296f05c..7f45428 100644 --- a/cascade.js +++ b/cascade.js @@ -347,21 +347,65 @@ class Cascade return await this.APICall("create",false,false,{folder: assetObject}); } + /** + * Do a move operation on a page, given a path, name, and folder. Unlike the Move and Rename operations in Cascade, + * which have separate functionality, this combines them into a single operation. + * + * @param {string} path Path or ID of the page to move. + * @param {string} newName New name of the page. If the asset is being moved to a different folder, this can be the same as the current name. + * @param {string} folderPath Path or ID of the folder to move to. If the asset is not being moved to a different folder, this can be the same as the current folder. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ async movePage(path,newName,folderPath) { return await this.doMove(path,newName,folderPath, "page"); } + /** + * Do a move operation on a file, given a path, name, and folder. Unlike the Move and Rename operations in Cascade, + * which have separate functionality, this combines them into a single operation. + * + * @param {string} path Path or ID of the file to move. + * @param {string} newName New name of the file. If the asset is being moved to a different folder, this can be the same as the current name. + * @param {string} folderPath Path or ID of the folder to move to. If the asset is not being moved to a different folder, this can be the same as the current folder. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ async moveFile(path,newName,folderPath) { return await this.doMove(path,newName,folderPath, "file"); } + /** + * Do a move operation on a folder, given a path, name, and folder. Unlike the Move and Rename operations in Cascade, + * which have separate functionality, this combines them into a single operation. + * + * @param {string} path Path or ID of the folder to move. + * @param {string} newName New name of the folder. If the asset is being moved to a different folder, this can be the same as the current name. + * @param {string} folderPath Path or ID of the folder to move to. If the asset is not being moved to a different folder, this can be the same as the current folder. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ async moveFolder(path,newName,folderPath) { return await this.doMove(path,newName,folderPath, "folder"); } + /** + * Do a move operation on an asset, given a path, name, folder, and type. Unlike the Move and Rename operations in Cascade, + * which have separate functionality, this combines them into a single operation. + * + * This should generally not be called directly, and instead a wrapper function like [movePage]{@link Cascade#movePage} or [moveFile]{@link Cascade#moveFile} should + * be used instead. But if you need to move or rename an asset that doesn't have a type this can be used. + * + * @param {string} path Path or ID of the asset to move. + * @param {string} newName New name of the asset. If the asset is being moved to a different folder, this can be the same as the current name. + * @param {string} folderPath Path or ID of the folder to move to. If the asset is not being moved to a different folder, this can be the same as the current folder. + * @param {string} type Type of the asset being moved. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ async doMove(path,newName,folderPath, type) { const moveParameters = { @@ -389,21 +433,56 @@ class Cascade return await this.APICall("move", type, path, false, {"moveParameters": moveParameters}); } + /** + * Make a copy of a a page, given a path, type, new name, and folder. + * @param {string} path Path or ID of page to copy. + * @param {string} newName New name of the page. If the asset is being copied to a different folder, this can be the same as the current name. + * @param {string} folderPath Path or ID of the folder to copy to. If the asset is not being copied to a different folder, this can be the same as the current folder. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ async copyPage(path,newName,folderPath) { return await this.makeCopy(path,newName,folderPath,"page"); } + /** + * Make a copy of a a file, given a path, type, new name, and folder. + * @param {string} path Path or ID of file to copy. + * @param {string} newName New name of the file. If the asset is being copied to a different folder, this can be the same as the current name. + * @param {string} folderPath Path or ID of the folder to copy to. If the asset is not being copied to a different folder, this can be the same as the current folder. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ async copyFile(path,newName,folderPath) { return await this.makeCopy(path,newName,folderPath,"file"); } + /** + * Make a copy of a a folder, given a path, type, new name, and folder. + * @param {string} path Path or ID of folder to copy. + * @param {string} newName New name of the folder. If the asset is being copied to a different folder, this can be the same as the current name. + * @param {string} folderPath Path or ID of the folder to copy to. If the asset is not being copied to a different folder, this can be the same as the current folder. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ async copyFolder(path,newName,folderPath) { return await this.makeCopy(path,newName,folderPath,"folder"); } + /** + * Make a copy of an asset, given a path, type, new name, and folder. This should generally not be called directly, + * and instead a wrapper method like [copyPage]{@link Cascade#copyPage} or [copyFile]{@link Cascade#copyFile} should + * be used. If the type doesn't have a wrapper function, this can be used instead. + * @param {string} path Path or ID of asset to copy. + * @param {string} newName New name of the item to use. If the asset is being copied to a different folder, this can be the same as the current name. + * @param {string} folderPath Path or ID of the folder to copy to. If the asset is not being copied to a different folder, this can be the same as the current folder. + * @param {string} type Type of the asset being copied. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ async makeCopy(path,newName,folderPath, type) { const copyParameters = { diff --git a/documentation/cascade-api.md b/documentation/cascade-api.md index fa3ebd6..6cbad40 100644 --- a/documentation/cascade-api.md +++ b/documentation/cascade-api.md @@ -37,7 +37,7 @@ Otherwise it will use a Cascade asset ID. You can swap modes using the [useId](# * [.createBlankPage()](#Cascade+createBlankPage) ⇒ [CascadeAsset](#CascadeAsset) * [.createBlankFile()](#Cascade+createBlankFile) ⇒ [CascadeAsset](#CascadeAsset) * [.createBlankFolder()](#Cascade+createBlankFolder) ⇒ [CascadeAsset](#CascadeAsset) - * [.APICall(operation, [type], [assetIDPath], [assetObject])](#Cascade+APICall) ⇒ Object + * [.APICall(operation, [type], [assetIDPath], [assetObject], [ajaxParameters])](#Cascade+APICall) ⇒ Object * [.readPage(path)](#Cascade+readPage) ⇒ Object * [.readFile(path)](#Cascade+readFile) ⇒ Object * [.readFolder(path)](#Cascade+readFolder) ⇒ Object @@ -53,6 +53,17 @@ Otherwise it will use a Cascade asset ID. You can swap modes using the [useId](# * [.createPage(assetObject)](#Cascade+createPage) ⇒ Object * [.createFile(assetObject)](#Cascade+createFile) ⇒ Object * [.createFolder(assetObject)](#Cascade+createFolder) ⇒ Object + * [.movePage(path, newName, folderPath)](#Cascade+movePage) ⇒ Object + * [.moveFile(path, newName, folderPath)](#Cascade+moveFile) ⇒ Object + * [.moveFolder(path, newName, folderPath)](#Cascade+moveFolder) ⇒ Object + * [.doMove(path, newName, folderPath, type)](#Cascade+doMove) ⇒ Object + * [.copyPage(path, newName, folderPath)](#Cascade+copyPage) ⇒ Object + * [.copyFile(path, newName, folderPath)](#Cascade+copyFile) ⇒ Object + * [.copyFolder(path, newName, folderPath)](#Cascade+copyFolder) ⇒ Object + * [.makeCopy(path, newName, folderPath, type)](#Cascade+makeCopy) ⇒ Object + * [.checkRelationshipsPage(path)](#Cascade+checkRelationshipsPage) ⇒ Object + * [.checkRelationshipsFile(path)](#Cascade+checkRelationshipsFile) ⇒ Object + * [.checkRelationshipsFolder(path)](#Cascade+checkRelationshipsFolder) ⇒ Object @@ -111,7 +122,7 @@ Return a blank folder, this is helpful when creating new assets. **Returns**: [CascadeAsset](#CascadeAsset) - Blank folder -### cascade.APICall(operation, [type], [assetIDPath], [assetObject]) ⇒ Object +### cascade.APICall(operation, [type], [assetIDPath], [assetObject], [ajaxParameters]) ⇒ Object Make an API call. Using the pre-defined functions is generally preferred, but if not all APIs have wrapper functions, this can be called directly. While most parameters are optional, most calls will need some number of them to be included. @@ -132,6 +143,7 @@ did not succeed. The error should be caught on the front end. | [type] | string | false | Optional. Required for calls where an identifier is needed (read, publish, etc). If not needed use default. | | [assetIDPath] | string | false | Optional. Either the path or id of the asset, needed where an identifier is needed, like type. If not needed use default. | | [assetObject] | Object | false | Optional. Asset to be acted upon, needed for some calls (create, edit). Must have an attribute for the asset type that's being acted upon (page, block, etc) | +| [ajaxParameters] | Object | false | Optional. Parameters to be added to the body, examples being copyParameters or moveParameters which are required for those operations. | @@ -379,6 +391,209 @@ but it can be created manually as well. | --- | --- | --- | | assetObject | Object | Cascade object representing the folder. | + + +### cascade.movePage(path, newName, folderPath) ⇒ Object +Do a move operation on a page, given a path, name, and folder. Unlike the Move and Rename operations in Cascade, +which have separate functionality, this combines them into a single operation. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of the page to move. | +| newName | string | New name of the page. If the asset is being moved to a different folder, this can be the same as the current name. | +| folderPath | string | Path or ID of the folder to move to. If the asset is not being moved to a different folder, this can be the same as the current folder. | + + + +### cascade.moveFile(path, newName, folderPath) ⇒ Object +Do a move operation on a file, given a path, name, and folder. Unlike the Move and Rename operations in Cascade, +which have separate functionality, this combines them into a single operation. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of the file to move. | +| newName | string | New name of the file. If the asset is being moved to a different folder, this can be the same as the current name. | +| folderPath | string | Path or ID of the folder to move to. If the asset is not being moved to a different folder, this can be the same as the current folder. | + + + +### cascade.moveFolder(path, newName, folderPath) ⇒ Object +Do a move operation on a folder, given a path, name, and folder. Unlike the Move and Rename operations in Cascade, +which have separate functionality, this combines them into a single operation. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of the folder to move. | +| newName | string | New name of the folder. If the asset is being moved to a different folder, this can be the same as the current name. | +| folderPath | string | Path or ID of the folder to move to. If the asset is not being moved to a different folder, this can be the same as the current folder. | + + + +### cascade.doMove(path, newName, folderPath, type) ⇒ Object +Do a move operation on an asset, given a path, name, folder, and type. Unlike the Move and Rename operations in Cascade, +which have separate functionality, this combines them into a single operation. + +This should generally not be called directly, and instead a wrapper function like [movePage](#Cascade+movePage) or [moveFile](#Cascade+moveFile) should +be used instead. But if you need to move or rename an asset that doesn't have a type this can be used. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of the asset to move. | +| newName | string | New name of the asset. If the asset is being moved to a different folder, this can be the same as the current name. | +| folderPath | string | Path or ID of the folder to move to. If the asset is not being moved to a different folder, this can be the same as the current folder. | +| type | string | Type of the asset being moved. | + + + +### cascade.copyPage(path, newName, folderPath) ⇒ Object +Make a copy of a a page, given a path, type, new name, and folder. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of page to copy. | +| newName | string | New name of the page. If the asset is being copied to a different folder, this can be the same as the current name. | +| folderPath | string | Path or ID of the folder to copy to. If the asset is not being copied to a different folder, this can be the same as the current folder. | + + + +### cascade.copyFile(path, newName, folderPath) ⇒ Object +Make a copy of a a file, given a path, type, new name, and folder. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of file to copy. | +| newName | string | New name of the file. If the asset is being copied to a different folder, this can be the same as the current name. | +| folderPath | string | Path or ID of the folder to copy to. If the asset is not being copied to a different folder, this can be the same as the current folder. | + + + +### cascade.copyFolder(path, newName, folderPath) ⇒ Object +Make a copy of a a folder, given a path, type, new name, and folder. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of folder to copy. | +| newName | string | New name of the folder. If the asset is being copied to a different folder, this can be the same as the current name. | +| folderPath | string | Path or ID of the folder to copy to. If the asset is not being copied to a different folder, this can be the same as the current folder. | + + + +### cascade.makeCopy(path, newName, folderPath, type) ⇒ Object +Make a copy of an asset, given a path, type, new name, and folder. This should generally not be called directly, +and instead a wrapper method like [copyPage](#Cascade+copyPage) or [copyFile](#Cascade+copyFile) should +be used. If the type doesn't have a wrapper function, this can be used instead. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of asset to copy. | +| newName | string | New name of the item to use. If the asset is being copied to a different folder, this can be the same as the current name. | +| folderPath | string | Path or ID of the folder to copy to. If the asset is not being copied to a different folder, this can be the same as the current folder. | +| type | string | Type of the asset being copied. | + + + +### cascade.checkRelationshipsPage(path) ⇒ Object +Check relationships for a page, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of page to check. | + + + +### cascade.checkRelationshipsFile(path) ⇒ Object +Check relationships for a file, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of file to check. | + + + +### cascade.checkRelationshipsFolder(path) ⇒ Object +Check relationships for a folder, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of folder to check. | + ## CascadeAsset diff --git a/test-cascade-api.js b/test-cascade-api.js index d57ec20..23b7b5c 100644 --- a/test-cascade-api.js +++ b/test-cascade-api.js @@ -3,7 +3,7 @@ const Cascade = require("./cascade.js"); // Replace values with your Cascade API URL, password, and site -const cascadeAPI = new Cascade("https://cascade.example.edu","username","password","site name"); +const cascadeAPI = new Cascade("https://cascade.georgefox.edu",{apiKey: "API_KEY"},"www Redesign"); // Example reading a page /* @@ -46,6 +46,19 @@ cascadeAPI.readFile("/template/t1/css/main.css") }); */ +// Exmaple reading a folder +/* +cascadeAPI.readFolder("/test") +.then(response=>{ + console.log("Success reading folder:"); + console.log(response); +}) +.catch(error=>{ + console.error("Erroring reading folder:"); + console.error(error); +}); +*/ + // Create New Page /* const newPage = cascadeAPI.createBlankPage(); @@ -113,6 +126,37 @@ cascadeAPI.deleteFile("/test/test.txt") }); */ +// Example creating a folder +/* +const newFolder = cascadeAPI.createBlankFolder(); +newFolder.siteName = cascadeAPI.site; +newFolder.parentFolderPath = "/test"; +newFolder.name = "test2"; +console.log(newFolder); +cascadeAPI.createFolder(newFolder) +.then(response=>{ + console.log("Success creating folder:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error creating folder:"); + console.error(error); +}); +*/ + +// Delete Folder +/* +cascadeAPI.deleteFolder("/test/test2") +.then(response=>{ + console.log("Success deleting folder:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error deleting folder:"); + console.error(error); +}); +*/ + // Example editing a page /* cascadeAPI.readPage("/test/test") @@ -159,6 +203,28 @@ cascadeAPI.readFile("/test/test.txt") }); */ +// Example editing a folder +/* +cascadeAPI.readFolder("/test/test2") +.then(response=>{ + console.log("Success reading folder:"); + const foundFolder = response.asset.folder; + foundFolder.name = "new-name"; + cascadeAPI.editFolder(foundFolder) + .then(response=>{ + console.log("Success editing folder:"); + console.log(response); + }) + .catch(error => { + console.errer("Error editing folder:"); + console.errer(error); + }); +}) +.catch(error=>{ + console.error("Error reading folder:"); + console.error(error); +}); +*/ // Example publishing a page /* @@ -186,9 +252,139 @@ cascadeAPI.publishFile("/test/test.txt") }); */ +// Example publishing a folder +/* +cascadeAPI.publishFolder("/test/test2") +.then(response=>{ + console.log("Success publishing folder:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error publishing folder:"); + console.error(error); +}); +*/ + +// Example checking relationships on a page +/* +cascadeAPI.checkRelationshipsPage("/test/page-1") +.then(response=>{ + console.log("Success getting relationships:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error getting relationships:"); + console.error(error); +}); +*/ + +// Example checking relationships on a file +/* +cascadeAPI.checkRelationshipsFile("/test/_assets-image-file-test/images/airplane.png") +.then(response=>{ + console.log("Success getting relationships:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error getting relationships:"); + console.error(error); +}); +*/ + +// Example checking relationships on a folder +/* +cascadeAPI.checkRelationshipsFolder("/test") +.then(response=>{ + console.log("Success getting relationships:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error getting relationships:"); + console.error(error); +}); +*/ + +// Example copying a page +/* +cascadeAPI.copyPage("/test/page","page-copy",{path:"/test"}) +.then(response=>{ + console.log("Copy succeeded"); + console.log(response); +}) +.catch(error=>{ + console.log("Copy failed"); + console.log(error); +}); +*/ + +// Example copying a file +/* +cascadeAPI.copyFile("/test/test-banner.jpg","test-banner-copy.jpg",{path:"/test"}) +.then(response=>{ + console.log("Copy succeeded"); + console.log(response); +}) +.catch(error=>{ + console.log("Copy failed"); + console.log(error); +}); +*/ + +// Example copying a folder +/* +cascadeAPI.copyFolder("/test/subfolder","subfolder-copy",{path:"/test"}) +.then(response=>{ + console.log("Copy succeeded"); + console.log(response); +}) +.catch(error=>{ + console.log("Copy failed"); + console.log(error); +}); +*/ + +// Example moving a page +/* +cascadeAPI.movePage("/test/page","page-new",{path:"/test"}) +.then(response=>{ + console.log("Move succeeded"); + console.log(response); +}) +.catch(error=>{ + console.log("Move failed"); + console.log(error); +}); +*/ + +// Example moving a file +/* +cascadeAPI.moveFile("/test/test-banner.jpg","test-banner-new.jpg",{path:"/test"}) +.then(response=>{ + console.log("Move succeeded"); + console.log(response); +}) +.catch(error=>{ + console.log("Move failed"); + console.log(error); +}); +*/ + +// Example moving a folder +/* +cascadeAPI.moveFolder("/test/subfolder","subfolder-new",{path:"/test"}) +.then(response=>{ + console.log("Move succeeded"); + console.log(response); +}) +.catch(error=>{ + console.log("Move failed"); + console.log(error); +}); +*/ + // Example making a direct API call /* -cascadeAPI.APICall("listSubscribers","page","/counseling-programs/index") +cascadeAPI.APICall("readAccessRights","page","/counseling-programs/index") .then(response=>{ console.log("Call succeeded"); console.log(response); From ea2604ff768f4cbf8ce99a707452593506457599 Mon Sep 17 00:00:00 2001 From: Peter Crackenberg Date: Mon, 28 Aug 2023 11:55:24 -0700 Subject: [PATCH 05/10] Added wrapper functions for blocks, a new utility function to return a blank block, and some examples in the test script. --- cascade.js | 114 ++++++++++++++++++++++++++++++++++++++++++-- test-cascade-api.js | 110 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 220 insertions(+), 4 deletions(-) diff --git a/cascade.js b/cascade.js index 7f45428..dd18024 100644 --- a/cascade.js +++ b/cascade.js @@ -70,7 +70,8 @@ class Cascade } /** - * Return a blank file, this is helpful when creating new assets. + * Return a blank file, this is helpful when creating new assets. This should either have information in the + * `data` attribute, or text in the `text` attribute. * @returns {CascadeAsset} Blank file */ createBlankFile() @@ -78,6 +79,16 @@ class Cascade return new CascadeAsset("file"); } + /** + * Return a blank XHTML/Data Definition block, this is helpful when creating new assets. This should either + * have properly escaped XHTML in the `xhtml` attribute, or a structured data object in the `structuredData` attribute. + * @returns {CascadeAsset} Blank block + */ + createBlankBlockDataDef() + { + return new CascadeAsset("xhtmlDataDefinition"); + } + /** * Return a blank folder, this is helpful when creating new assets. * @returns {CascadeAsset} Blank folder @@ -198,6 +209,17 @@ class Cascade return await this.APICall("read","file",path); } + /** + * Read a block, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + * @param {string} path Path or ID of block to read + * @returns {Object} Object representing the Cascade response. Block that was found will depend on what type of block it was + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async readBlock(path) + { + return await this.APICall("read","block",path); + } + /** * Read a folder, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. * @param {string} path Path or ID of folder to read @@ -231,6 +253,17 @@ class Cascade return await this.APICall("delete","file",path); } + /** + * Delete a block, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + * @param {string} path Path or ID of block to delete + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async deleteBlock(path) + { + return await this.APICall("delete","block",path); + } + /** * Delete a folder, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. * @param {string} path Path or ID of folder to delete @@ -255,7 +288,7 @@ class Cascade } /** - * Edit a file, given a Cascade file object. Typically the page to edit is read in via [readFile]{@link Cascade#readFile}, + * Edit a file, given a Cascade file object. Typically the file to edit is read in via [readFile]{@link Cascade#readFile}, * but it can be manually created as well. * @param {Object} assetObject Cascade object representing the file. * @returns {Object} Object representing the Cascade response. @@ -267,7 +300,23 @@ class Cascade } /** - * Edit a folder, given a Cascade folder object. Typically the page to edit is read in via [readFolder]{@link Cascade#readFolder}, + * Edit a block, given a Cascade block object. Typically the block to edit is read in via [readBlock]{@link Cascade#readBlock}, + * but it can be manually created as well. + * + * Unlike other assets, blocks need to specify + * + * @param {Object} assetObject Cascade object representing the block. + * @param {string} [blockType=xhtmlDataDefinitionBlock] Type of the block to interact with, this defaults to an XHTML/Data Defintion Block + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async editBlock(assetObject, blockType="xhtmlDataDefinitionBlock") + { + return await this.APICall("edit","block",assetObject.path,{[blockType]: assetObject}); + } + + /** + * Edit a folder, given a Cascade folder object. Typically the folder to edit is read in via [readFolder]{@link Cascade#readFolder}, * but it can be manually created as well. * @param {Object} assetObject Cascade object representing the folder. * @returns {Object} Object representing the Cascade response. @@ -335,6 +384,19 @@ class Cascade return await this.APICall("create",false,false,{file: assetObject}); } + /** + * Create a block, given a Cascade block object. Typically this is created using [createBlankBlockDataDef]{@link Cascade#createBlankBlockDataDef}, + * but it can be created manually as well. + * @param {Object} assetObject Cascade object representing the block. + * @param {string} [blockType=xhtmlDataDefinitionBlock] Type of the block to interact with, this defaults to an XHTML/Data Defintion Block + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async createBlock(assetObject, blockType="xhtmlDataDefinitionBlock") + { + return await this.APICall("create",false,false,{[blockType]: assetObject}); + } + /** * Create a folder, given a Cascade folder object. Typically this is created using [createBlankFolder]{@link Cascade#createBlankFolder}, * but it can be created manually as well. @@ -377,6 +439,21 @@ class Cascade return await this.doMove(path,newName,folderPath, "file"); } + /** + * Do a move operation on a block, given a path, name, and folder. Unlike the Move and Rename operations in Cascade, + * which have separate functionality, this combines them into a single operation. + * + * @param {string} path Path or ID of the block to move. + * @param {string} newName New name of the block. If the asset is being moved to a different folder, this can be the same as the current name. + * @param {string} folderPath Path or ID of the block to move to. If the asset is not being moved to a different folder, this can be the same as the current folder. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async moveBlock(path,newName,folderPath) + { + return await this.doMove(path,newName,folderPath, "block"); + } + /** * Do a move operation on a folder, given a path, name, and folder. Unlike the Move and Rename operations in Cascade, * which have separate functionality, this combines them into a single operation. @@ -459,6 +536,19 @@ class Cascade return await this.makeCopy(path,newName,folderPath,"file"); } + /** + * Make a copy of a a block, given a path, type, new name, and folder. + * @param {string} path Path or ID of block to copy. + * @param {string} newName New name of the block. If the asset is being copied to a different folder, this can be the same as the current name. + * @param {string} folderPath Path or ID of the folder to copy to. If the asset is not being copied to a different folder, this can be the same as the current folder. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async copyBlock(path,newName,folderPath) + { + return await this.makeCopy(path,newName,folderPath,"block"); + } + /** * Make a copy of a a folder, given a path, type, new name, and folder. * @param {string} path Path or ID of folder to copy. @@ -532,6 +622,17 @@ class Cascade return await this.APICall("listSubscribers","file",path); } + /** + * Check relationships for a file, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + * @param {string} path Path or ID of file to check. + * @returns {Object} Object representing the Cascade response. + * @throws Will throw an error if the Cascade API operation was not successful. + */ + async checkRelationshipsBlock(path) + { + return await this.APICall("listSubscribers","block",path); + } + /** * Check relationships for a folder, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. * @param {string} path Path or ID of folder to check. @@ -577,6 +678,13 @@ class CascadeAsset displayName: "" }; } + else if(type == "xhtmlDataDefinitionBlock") + { + this.metadataSetId = ""; + this.metadataSetPath = ""; + this.xhtml = ""; + this.structuredData = {}; + } else if(type == "file") { this.data = []; diff --git a/test-cascade-api.js b/test-cascade-api.js index 23b7b5c..e9cb3d6 100644 --- a/test-cascade-api.js +++ b/test-cascade-api.js @@ -35,7 +35,7 @@ cascadeAPI.readPage("96dc63ca0a0a008468d68542746cfd37") // Example reading a file /* -cascadeAPI.readFile("/template/t1/css/main.css") +cascadeAPI.readFile("/test/file.css") .then(response=>{ console.log("Success reading file:"); console.log(response); @@ -59,6 +59,19 @@ cascadeAPI.readFolder("/test") }); */ +// Example reading a block +/* +cascadeAPI.readBlock("/test/test-block") +.then(response=>{ + console.log("Success reading block:"); + console.log(response); +}) +.catch(error=>{ + console.log("Error reading block:"); + console.log(error); +}); +*/ + // Create New Page /* const newPage = cascadeAPI.createBlankPage(); @@ -157,6 +170,39 @@ cascadeAPI.deleteFolder("/test/test2") }); */ +// Example creating a block +/* +const newBlock = cascadeAPI.createBlankBlockDataDef(); +newBlock.siteName = cascadeAPI.site; +newBlock.parentFolderPath = "/test/_assets-page-1"; +newBlock.name = "test-block"; +newBlock.metadataSetPath = "Default"; +newBlock.xhtml = "

Test content

"; +console.log(newBlock); +cascadeAPI.createBlock(newBlock) +.then(response=>{ + console.log("Success creating block:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error creating block:"); + console.error(error); +}); +*/ + +// Delete block +/* +cascadeAPI.deleteBlock("/test/test-block") +.then(response=>{ + console.log("Success deleting block:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error deleting block:"); + console.error(error); +}); +*/ + // Example editing a page /* cascadeAPI.readPage("/test/test") @@ -226,6 +272,29 @@ cascadeAPI.readFolder("/test/test2") }); */ +// Example editing a block +/* +cascadeAPI.readBlock("/test/test-block") +.then(response=>{ + console.log("Success reading block:"); + const foundBlock = response.asset.xhtmlDataDefinitionBlock; + foundBlock.xhtml = "

New content

"; + cascadeAPI.editBlock(foundBlock) + .then(response=>{ + console.log("Success editing block:"); + console.log(response); + }) + .catch(error => { + console.errer("Error editing block:"); + console.errer(error); + }); +}) +.catch(error=>{ + console.error("Error reading block:"); + console.error(error); +}); +*/ + // Example publishing a page /* cascadeAPI.publishPage("/test/test") @@ -304,6 +373,19 @@ cascadeAPI.checkRelationshipsFolder("/test") }); */ +// Example checking relationships on a block +/* +cascadeAPI.checkRelationshipsBlock("/test/block") +.then(response=>{ + console.log("Success getting relationships:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error getting relationships:"); + console.error(error); +}); +*/ + // Example copying a page /* cascadeAPI.copyPage("/test/page","page-copy",{path:"/test"}) @@ -343,6 +425,19 @@ cascadeAPI.copyFolder("/test/subfolder","subfolder-copy",{path:"/test"}) }); */ +// Example copying a block +/* +cascadeAPI.copyBlock("/test/test-block","test-block-copy",{path:"/test"}) +.then(response=>{ + console.log("Copy succeeded"); + console.log(response); +}) +.catch(error=>{ + console.log("Copy failed"); + console.log(error); +}); +*/ + // Example moving a page /* cascadeAPI.movePage("/test/page","page-new",{path:"/test"}) @@ -382,6 +477,19 @@ cascadeAPI.moveFolder("/test/subfolder","subfolder-new",{path:"/test"}) }); */ +// Example moving a block +/* +cascadeAPI.moveBlock("/test/test-block","test-block-new",{path:"/test"}) +.then(response=>{ + console.log("Move succeeded"); + console.log(response); +}) +.catch(error=>{ + console.log("Move failed"); + console.log(error); +}); +*/ + // Example making a direct API call /* cascadeAPI.APICall("readAccessRights","page","/counseling-programs/index") From 7f7c7e9cdf41ab6aed2c9869919edd9e769fbad7 Mon Sep 17 00:00:00 2001 From: Peter Crackenberg Date: Mon, 28 Aug 2023 11:56:35 -0700 Subject: [PATCH 06/10] Fixed the site name to be more generic. --- test-cascade-api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-cascade-api.js b/test-cascade-api.js index e9cb3d6..149a3ef 100644 --- a/test-cascade-api.js +++ b/test-cascade-api.js @@ -3,7 +3,7 @@ const Cascade = require("./cascade.js"); // Replace values with your Cascade API URL, password, and site -const cascadeAPI = new Cascade("https://cascade.georgefox.edu",{apiKey: "API_KEY"},"www Redesign"); +const cascadeAPI = new Cascade("https://cascade.georgefox.edu",{apiKey: "API_KEY"},"SITE_NAME"); // Example reading a page /* From 892856056363cbe0fd40a173d8d9afdacce6d1de Mon Sep 17 00:00:00 2001 From: Peter Crackenberg Date: Mon, 28 Aug 2023 13:30:23 -0700 Subject: [PATCH 07/10] Fixed a path in the test file. --- test-cascade-api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-cascade-api.js b/test-cascade-api.js index 149a3ef..0d0e21e 100644 --- a/test-cascade-api.js +++ b/test-cascade-api.js @@ -174,7 +174,7 @@ cascadeAPI.deleteFolder("/test/test2") /* const newBlock = cascadeAPI.createBlankBlockDataDef(); newBlock.siteName = cascadeAPI.site; -newBlock.parentFolderPath = "/test/_assets-page-1"; +newBlock.parentFolderPath = "/test"; newBlock.name = "test-block"; newBlock.metadataSetPath = "Default"; newBlock.xhtml = "

Test content

"; From 2276e70f9e1cc6e15129b7daa11a50e43103f239 Mon Sep 17 00:00:00 2001 From: Peter Crackenberg Date: Mon, 28 Aug 2023 13:30:41 -0700 Subject: [PATCH 08/10] Added block function examples. --- README.md | 1 + documentation/block-functions.md | 97 ++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 documentation/block-functions.md diff --git a/README.md b/README.md index e3e24f0..06d634b 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ Examples will use the variable `cascadeAPI` from above. These examples use paths * [Page Functions](documentation/page-functions.md) * [File Functions](documentation/file-functions.md) * [Folder Functions](documentation/folder-functions.md) +* [Block Functions](documentation/block-functions.md) * [Other API Uses](documentation/other-api.md) ## Full Documentation diff --git a/documentation/block-functions.md b/documentation/block-functions.md new file mode 100644 index 0000000..40bf34e --- /dev/null +++ b/documentation/block-functions.md @@ -0,0 +1,97 @@ +# Block Functions + +## Read Block + +```javascript +cascadeAPI.readBlock("/test/test-block") +.then(response=>{ + console.log("Success reading block:"); + console.log(response); +}) +.catch(error=>{ + console.log("Error reading block:"); + console.log(error); +}); +``` + +## Edit Block +This example uses a data definition block, which is the default type, but if a different type of block needs to be edited an optional +`blockType` parameter can be sent in to the read function. If the block is a data defintion block, the `structuredData` property should +be updated instead of the `xhtml` property that is changed here. +```javascript +cascadeAPI.readBlock("/test/test-block") +.then(response=>{ + console.log("Success reading block:"); + const foundBlock = response.asset.xhtmlDataDefinitionBlock; + foundBlock.xhtml = "

New content

"; + cascadeAPI.editBlock(foundBlock) + .then(response=>{ + console.log("Success editing block:"); + console.log(response); + }) + .catch(error => { + console.errer("Error editing block:"); + console.errer(error); + }); +}) +.catch(error=>{ + console.error("Error reading block:"); + console.error(error); +}); +``` + +## Create Block +When creating a new block, you must send Cascade the asset you'd like to create. You can use the `createBlankBlockDataDef()` helper function to return a blank asset that you can then edit with the values you want. You can also manually create the object if you need a block of a different type, or if +you just want to work with it manually. + +This example uses a data definition block, which is the default type, but if a different type of block needs to be edited an optional +`blockType` parameter can be sent in to the read function. If the block is a data defintion block, the `structuredData` property should +be updated instead of the `xhtml` property that is changed here. + +The asset ID of the newly created page will be returned on success. +```javascript +const newBlock = cascadeAPI.createBlankBlockDataDef(); +newBlock.siteName = cascadeAPI.site; +newBlock.parentFolderPath = "/test"; +newBlock.name = "test-block"; +newBlock.metadataSetPath = "Default"; +newBlock.xhtml = "

Test content

"; +console.log(newBlock); +cascadeAPI.createBlock(newBlock) +.then(response=>{ + console.log("Success creating block:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error creating block:"); + console.error(error); +}); +``` + +## Delete Block + +```javascript +cascadeAPI.deleteBlock("/test/test-block") +.then(response=>{ + console.log("Success deleting block:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error deleting block:"); + console.error(error); +}); +``` + +## Check Block Relationships + +```javascript +cascadeAPI.checkRelationshipsBlock("/test/block") +.then(response=>{ + console.log("Success getting relationships:"); + console.log(response); +}) +.catch(error=>{ + console.error("Error getting relationships:"); + console.error(error); +}); +``` \ No newline at end of file From 74ba310bd7103151e3b9578d7090a7b9360e848e Mon Sep 17 00:00:00 2001 From: Peter Crackenberg Date: Mon, 28 Aug 2023 13:31:18 -0700 Subject: [PATCH 09/10] Recreated docs after adding new functions. --- documentation/cascade-api.md | 146 ++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 3 deletions(-) diff --git a/documentation/cascade-api.md b/documentation/cascade-api.md index 6cbad40..366689c 100644 --- a/documentation/cascade-api.md +++ b/documentation/cascade-api.md @@ -36,33 +36,41 @@ Otherwise it will use a Cascade asset ID. You can swap modes using the [useId](# * [.useId()](#Cascade+useId) * [.createBlankPage()](#Cascade+createBlankPage) ⇒ [CascadeAsset](#CascadeAsset) * [.createBlankFile()](#Cascade+createBlankFile) ⇒ [CascadeAsset](#CascadeAsset) + * [.createBlankBlockDataDef()](#Cascade+createBlankBlockDataDef) ⇒ [CascadeAsset](#CascadeAsset) * [.createBlankFolder()](#Cascade+createBlankFolder) ⇒ [CascadeAsset](#CascadeAsset) * [.APICall(operation, [type], [assetIDPath], [assetObject], [ajaxParameters])](#Cascade+APICall) ⇒ Object * [.readPage(path)](#Cascade+readPage) ⇒ Object * [.readFile(path)](#Cascade+readFile) ⇒ Object + * [.readBlock(path)](#Cascade+readBlock) ⇒ Object * [.readFolder(path)](#Cascade+readFolder) ⇒ Object * [.deletePage(path)](#Cascade+deletePage) ⇒ Object * [.deleteFile(path)](#Cascade+deleteFile) ⇒ Object + * [.deleteBlock(path)](#Cascade+deleteBlock) ⇒ Object * [.deleteFolder(path)](#Cascade+deleteFolder) ⇒ Object * [.editPage(assetObject)](#Cascade+editPage) ⇒ Object * [.editFile(assetObject)](#Cascade+editFile) ⇒ Object + * [.editBlock(assetObject, [blockType])](#Cascade+editBlock) ⇒ Object * [.editFolder(assetObject)](#Cascade+editFolder) ⇒ Object * [.publishPage(path)](#Cascade+publishPage) ⇒ Object * [.publishFile(path)](#Cascade+publishFile) ⇒ Object * [.publishFolder(path)](#Cascade+publishFolder) ⇒ Object * [.createPage(assetObject)](#Cascade+createPage) ⇒ Object * [.createFile(assetObject)](#Cascade+createFile) ⇒ Object + * [.createBlock(assetObject, [blockType])](#Cascade+createBlock) ⇒ Object * [.createFolder(assetObject)](#Cascade+createFolder) ⇒ Object * [.movePage(path, newName, folderPath)](#Cascade+movePage) ⇒ Object * [.moveFile(path, newName, folderPath)](#Cascade+moveFile) ⇒ Object + * [.moveBlock(path, newName, folderPath)](#Cascade+moveBlock) ⇒ Object * [.moveFolder(path, newName, folderPath)](#Cascade+moveFolder) ⇒ Object * [.doMove(path, newName, folderPath, type)](#Cascade+doMove) ⇒ Object * [.copyPage(path, newName, folderPath)](#Cascade+copyPage) ⇒ Object * [.copyFile(path, newName, folderPath)](#Cascade+copyFile) ⇒ Object + * [.copyBlock(path, newName, folderPath)](#Cascade+copyBlock) ⇒ Object * [.copyFolder(path, newName, folderPath)](#Cascade+copyFolder) ⇒ Object * [.makeCopy(path, newName, folderPath, type)](#Cascade+makeCopy) ⇒ Object * [.checkRelationshipsPage(path)](#Cascade+checkRelationshipsPage) ⇒ Object * [.checkRelationshipsFile(path)](#Cascade+checkRelationshipsFile) ⇒ Object + * [.checkRelationshipsBlock(path)](#Cascade+checkRelationshipsBlock) ⇒ Object * [.checkRelationshipsFolder(path)](#Cascade+checkRelationshipsFolder) ⇒ Object @@ -109,10 +117,19 @@ Return a blank page, this is helpful when creating new assets. ### cascade.createBlankFile() ⇒ [CascadeAsset](#CascadeAsset) -Return a blank file, this is helpful when creating new assets. +Return a blank file, this is helpful when creating new assets. This should either have information in the +`data` attribute, or text in the `text` attribute. **Kind**: instance method of [Cascade](#Cascade) **Returns**: [CascadeAsset](#CascadeAsset) - Blank file + + +### cascade.createBlankBlockDataDef() ⇒ [CascadeAsset](#CascadeAsset) +Return a blank XHTML/Data Definition block, this is helpful when creating new assets. This should either +have properly escaped XHTML in the `xhtml` attribute, or a structured data object in the `structuredData` attribute. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: [CascadeAsset](#CascadeAsset) - Blank block ### cascade.createBlankFolder() ⇒ [CascadeAsset](#CascadeAsset) @@ -177,6 +194,22 @@ Read a file, given a path or ID (depending on the mode of the Cascade object) an | --- | --- | --- | | path | string | Path or ID of file to read | + + +### cascade.readBlock(path) ⇒ Object +Read a block, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. Block that was found will depend on what type of block it was +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of block to read | + ### cascade.readFolder(path) ⇒ Object @@ -225,6 +258,22 @@ Delete a file, given a path or ID (depending on the mode of the Cascade object) | --- | --- | --- | | path | string | Path or ID of file to delete | + + +### cascade.deleteBlock(path) ⇒ Object +Delete a block, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of block to delete | + ### cascade.deleteFolder(path) ⇒ Object @@ -261,7 +310,7 @@ but it can be manually created as well. ### cascade.editFile(assetObject) ⇒ Object -Edit a file, given a Cascade file object. Typically the page to edit is read in via [readFile](#Cascade+readFile), +Edit a file, given a Cascade file object. Typically the file to edit is read in via [readFile](#Cascade+readFile), but it can be manually created as well. **Kind**: instance method of [Cascade](#Cascade) @@ -275,10 +324,30 @@ but it can be manually created as well. | --- | --- | --- | | assetObject | Object | Cascade object representing the file. | + + +### cascade.editBlock(assetObject, [blockType]) ⇒ Object +Edit a block, given a Cascade block object. Typically the block to edit is read in via [readBlock](#Cascade+readBlock), +but it can be manually created as well. + +Unlike other assets, blocks need to specify + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| assetObject | Object | | Cascade object representing the block. | +| [blockType] | string | "xhtmlDataDefinitionBlock" | Type of the block to interact with, this defaults to an XHTML/Data Defintion Block | + ### cascade.editFolder(assetObject) ⇒ Object -Edit a folder, given a Cascade folder object. Typically the page to edit is read in via [readFolder](#Cascade+readFolder), +Edit a folder, given a Cascade folder object. Typically the folder to edit is read in via [readFolder](#Cascade+readFolder), but it can be manually created as well. **Kind**: instance method of [Cascade](#Cascade) @@ -374,6 +443,24 @@ but it can be created manually as well. | --- | --- | --- | | assetObject | Object | Cascade object representing the file. | + + +### cascade.createBlock(assetObject, [blockType]) ⇒ Object +Create a block, given a Cascade block object. Typically this is created using [createBlankBlockDataDef](#Cascade+createBlankBlockDataDef), +but it can be created manually as well. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| assetObject | Object | | Cascade object representing the block. | +| [blockType] | string | "xhtmlDataDefinitionBlock" | Type of the block to interact with, this defaults to an XHTML/Data Defintion Block | + ### cascade.createFolder(assetObject) ⇒ Object @@ -429,6 +516,25 @@ which have separate functionality, this combines them into a single operation. | newName | string | New name of the file. If the asset is being moved to a different folder, this can be the same as the current name. | | folderPath | string | Path or ID of the folder to move to. If the asset is not being moved to a different folder, this can be the same as the current folder. | + + +### cascade.moveBlock(path, newName, folderPath) ⇒ Object +Do a move operation on a block, given a path, name, and folder. Unlike the Move and Rename operations in Cascade, +which have separate functionality, this combines them into a single operation. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of the block to move. | +| newName | string | New name of the block. If the asset is being moved to a different folder, this can be the same as the current name. | +| folderPath | string | Path or ID of the block to move to. If the asset is not being moved to a different folder, this can be the same as the current folder. | + ### cascade.moveFolder(path, newName, folderPath) ⇒ Object @@ -507,6 +613,24 @@ Make a copy of a a file, given a path, type, new name, and folder. | newName | string | New name of the file. If the asset is being copied to a different folder, this can be the same as the current name. | | folderPath | string | Path or ID of the folder to copy to. If the asset is not being copied to a different folder, this can be the same as the current folder. | + + +### cascade.copyBlock(path, newName, folderPath) ⇒ Object +Make a copy of a a block, given a path, type, new name, and folder. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of block to copy. | +| newName | string | New name of the block. If the asset is being copied to a different folder, this can be the same as the current name. | +| folderPath | string | Path or ID of the folder to copy to. If the asset is not being copied to a different folder, this can be the same as the current folder. | + ### cascade.copyFolder(path, newName, folderPath) ⇒ Object @@ -574,6 +698,22 @@ Check relationships for a file, given a path or ID (depending on the mode of the - Will throw an error if the Cascade API operation was not successful. +| Param | Type | Description | +| --- | --- | --- | +| path | string | Path or ID of file to check. | + + + +### cascade.checkRelationshipsBlock(path) ⇒ Object +Check relationships for a file, given a path or ID (depending on the mode of the Cascade object) and return a Cascade response. + +**Kind**: instance method of [Cascade](#Cascade) +**Returns**: Object - Object representing the Cascade response. +**Throws**: + +- Will throw an error if the Cascade API operation was not successful. + + | Param | Type | Description | | --- | --- | --- | | path | string | Path or ID of file to check. | From cc86294282c1e45762962a32237a67d98095ff71 Mon Sep 17 00:00:00 2001 From: Peter Crackenberg Date: Mon, 28 Aug 2023 13:37:03 -0700 Subject: [PATCH 10/10] Fixed example site in the test file. --- test-cascade-api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-cascade-api.js b/test-cascade-api.js index 0d0e21e..2660f59 100644 --- a/test-cascade-api.js +++ b/test-cascade-api.js @@ -3,7 +3,7 @@ const Cascade = require("./cascade.js"); // Replace values with your Cascade API URL, password, and site -const cascadeAPI = new Cascade("https://cascade.georgefox.edu",{apiKey: "API_KEY"},"SITE_NAME"); +const cascadeAPI = new Cascade("https://cascade.example.edu",{apiKey: "API_KEY"},"SITE_NAME"); // Example reading a page /*