IafScripts
Use the IafScript API to create and manage scripts and script versions on the platform.
create#
Creates scripts and returns an array of the created Script objects.
| Parameter | Required | Type | Description |
|---|---|---|---|
| scripts | Yes | Array<Script> | Pass an array of Script objects to create. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Array<Script> - Returns an array of the created Script objects
const scripts = await IafScripts.create(scriptsArray);createScript#
Creates an array of Script class objects and returns a Page object with the created Script objects.
| Parameter | Required | Type | Description |
|---|---|---|---|
| scripts | Yes | Array<Script> | Pass an array of Script objects to create. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Page<Array<Script>> - Returns a Page object with the created Script objects
const createdScripts = await IafScripts.createScript(scriptsArray);createVersion#
Creates a ScriptVersion class object.
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | Pass the Script's id. |
| version | Yes | ScriptVersion | Pass a ScriptVersion object with a "_userData" property and the script content as its value. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
ScriptVersion - The created ScriptVersion object
const version = { _userData: "<YOUR_SCRIPT_CONTENT_HERE>" };
const scriptVersion = await IafScripts.createVersion(id, version);delete#
Deletes a Script class object from the Item Service.
| Parameter | Required | Type | Description |
|---|---|---|---|
| script | Yes | Script | Pass the Script object you want to delete. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
String - 204 response {ok:204}
const response = await IafScript.delete(script);deleteVersion#
Deletes a ScriptVersion when you pass its id.
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | Pass the Script's id. |
| versionId | Yes | String | Pass the ScriptVersion's id. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
String - 204 response {ok:204}
const response = await IafScripts.deleteVersion(id, versionId);getById#
Gets a Script when you pass its id.
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | The Script's id |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Script - Returns the created Script object
const script = await IafScript.getById(id);getByName#
Gets Scripts when you pass a name.
| Parameter | Required | Type | Description |
|---|---|---|---|
| name | Yes | String | Pass the Script's "_name" property's value. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
Array<Script> - An array of Scripts that match the name you pass.
const scripts = await IafScripts.getByName("project_setup_script_3");getScripts#
Gets scripts that match your query.
| Parameter | Required | Type | Description |
|---|---|---|---|
| criteria | Yes | NamedUserItemCriteria | Pass a NamedUserItemCriteria object with your query. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
| options | Yes | ItemSvcOptions | Pass an ItemSvcOptions object with your response pagination options, such as "_page", "_project", "_offset", and "_sort". |
Array<Script> - A Page object with an array of Scripts that match your query.
const criteria = { _usertype: "project_setup" };const options = { _project: "_userData" };
const setupScripts = await IafScript.getScriptsWithPagination(criteria, options);getScriptsWithPagination#
Gets a Page of Script class objects that match your query.
| Parameter | Required | Type | Description |
|---|---|---|---|
| criteria | Yes | NamedUserItemCriteria | Pass a NamedUserItemCriteria object with your query. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
| options | Yes | ItemSvcOptions | Pass an ItemSvcOptions object with your response pagination options, such as "_pageSize", "_project", "_offset", and "_sort". |
Page<Array<Script>> - A Page object with an array of Scripts that match your query.
const criteria = { _usertype: "project_setup" };const options = { _project: "_userData" };
const setupScripts = await IafScript.getScriptsWithPagination(criteria, options);getVersionById#
Gets a ScriptVersion when you pass its id.
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | Pass the Script's id. |
| versionId | Yes | String | Pass the ScriptVersion's id. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
const scriptVersion = await IafScripts.getVersionById(id, versionId);getVersions#
Gets a Script's versions.
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | Pass the Script's id. |
| criteria | No | NamedUserItemVersionCriteria | Pass a simple query to match the versions you want. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
| options | Yes | JSON | Pass an object with your response pagination options, such as "_page", "_project", "_offset", and "_sort".Pass an ItemSvcOptions object with your response pagination options, such as "_page", "_project", "_offset", and "_sort". |
Array<ScriptVersion> - An array of ScriptVersion class objects.
const criteria = { createdDate : { "$gt" : "2016-04-09T08:28:47" }};
const versions = await IafScripts.getVersions(script._id, criteria);isValid#
Checks if the script content for a Script class object is valid.
| Parameter | Required | Type | Description |
|---|---|---|---|
| script | Yes | String | Pass the script content you want to validate. |
boolean - Returns true if the script content is valid.
const isValid = IafScripts.isValid(myScriptContent);isValidJSCode#
Checks if a script's content is valid JavaScript.
| Parameter | Required | Type | Description |
|---|---|---|---|
| script | Yes | String | Pass the script content you want to validate. |
boolean/object - Returns true if the JavaScript is valid. If the JavaScript is not valid, an ErrorObject returns.
const isValid = IafScripts.isValidJSCode(myScriptContent);update#
Updates a Script object that already exits. To update a Script's content, use updateScriptVersion.
| Parameter | Required | Type | Description |
|---|---|---|---|
| script | Yes | Script | Pass the Script object with updated properties or values. |
| ctx | No | ctx | Context, such as namespaces and authentication token information. |
Script - The updated Script object
//Update scriptconst scriptObj = { _id: "5c931fddb834740001251982", _name: "Project setup script", _shortName: "prjSetup", _userType: "project_setup_script_updated"};
const script = await IafScripts.update(project,scriptObj,ctx);updateVersion#
Updates the script content of a specific ScriptVersion.
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | Pass the script's id. |
| version | Yes | ScriptVersion | Pass a ScriptVersion object with a "_userData" property and the updated script content as its value. |
| ctx | No | Ctx | Context, such as namespaces and authentication token information. |
ScriptVersion - The updated ScriptVersion object
const version = { _userData: "<YOUR_SCRIPT_CONTENT_HERE> };
const updatedScriptVersion = await IafScripts.updateVersion(id, version);