Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

osaton/studio-helper

Repository files navigation

Archived Repository

Repository Archived and Moved

This repository has been archived and is no longer actively maintained. The project has been moved to a private repository.

However, the related npm package is still available and can be accessed and used as before: npm install studio-helper

Classes

StudioHelper

Typedefs

ApiResponse : Object
ResultObj : Object
ProgressOptions
FileHeaderSettings : Object

Key / value pairs of wanted header names and their values

CreateFolderResult : Object
FolderSettings : Object
FolderUpdateSettings : Object

StudioHelper

Kind: global class

new StudioHelper(settings)

Param Type Default Description
settings Object
settings.studio string Studio host ('xyz.studio.crasman.fi')
[settings.proxy] string Proxy
[settings.strictSSL] boolean true Change to false if you're using self-signed certificate
[settings.loginPromptEnabled] boolean true Show login prompt if authentication fails
[settings.credentialsFile] string ".studio-credentials" File in which credentials are saved
[settings.useCacheDir] boolean false Store credentials file in Node modules cache dir
[settings.concurrentUploads] number 1 Max concurrent uploads when using batch methods. Defaul 1, Max 5.
[settings.ignoreFile] string ".studio-ignore" Utilised by push method. Uses gitignore spec

Example

var StudioHelper = require('studio-helper'),
    studio = new StudioHelper({
      studio: 'xyz.studio.crasman.fi',
      proxy: 'http://xyz.intra:8080/'
    });

studioHelper.login(username, password, token, [longSession]) ⇒ Promise

Login

Kind: instance method of StudioHelper

Param Type Default
username string
password string
token string
[longSession] int 1

studioHelper.updateSessionSetting(setting, value)

Update a single setting for this session

See documentation for available settings.

Kind: instance method of StudioHelper
See: Documentation

Param Type
setting string
value string

studioHelper.resetSessionSettings()

Reset all API settings to default values

Kind: instance method of StudioHelper

studioHelper.getAllFolders([limit], [offset]) ⇒ Promise.<ApiResponse.<Array.<{id: string, name: string, parentId: (null|string), createdAt: number, modifiedAt: number}>>>

Get all folders in Studio

Kind: instance method of StudioHelper

Param Type Default Description
[limit] number 1000 Max number of folders to return. Max 1000, default 1000.
[offset] number 0 Offset

studioHelper.getMetadataFields() ⇒ Promise.<ApiResponse.<Array.<{id: string, fields: {id: string, type: string, names: Object}, languages: Array.<string>}>>>

Get all metadata fields defined in Stage for this Studio

Kind: instance method of StudioHelper
Example
return value

// {
//   "status": "ok",
//   "result": [
//     {
//       "id": "my_table",
//       "fields": [
//         {
//           "id": "my_field",
//           "type": "st",
//           "names": {
//             "en": "My field"
//           }
//         }
//       ],
//       "languages": [
//         "en"
//       ]
//     }
//   ],
//   "code": 0
// }

studioHelper.getConversions() ⇒ Promise.<ApiResponse.<Array.<{id: string, name: string}>>>

Kind: instance method of StudioHelper
Example
return value

// {
//   "status": "ok",
//   "result": [
//     {
//       "id": "my_conversion",
//       "name": "My conversion",
//     }
//   ],
//   "code": 0
// }

studioHelper.push(settings) ⇒ Array.<Object>

Push changes to Studio

Kind: instance method of StudioHelper
Returns: Array.<Object> - Array of objects with file upload information. Array has data property which contains additional information.

Param Type Default Description
settings Object
settings.folders Array.<Object>
settings.folders[].folderId string Studio folder id
settings.folders[].localFolder string Local folder path
[settings.folders[].createNewFileVersions] boolean true Create new versions of uploaded / updated files. Use false to save disk space if you don't need version history.
[settings.folders[].includeSubFolders] boolean false Create and upload sub folders
[settings.folders[].createdFolderSettings] Object Object with paths (RegEx pattern) as keys and FolderUpdateSettings object as value. See example.
[settings.folders[].createdFileHeaders] Object Object with file paths (RegEx pattern) as keys and FileHeaderSettings objcet as value. See example.

Example

studio.push({
  folders: [{
    folderId: '568a7a2aadd4532b0f4f4f5b',
    localFolder: 'dist/js'
  }, {
    folderId: '568a7a27add453aa1a4f4f58',
    localFolder: 'dist/css'
  }, {
    folderId: '568a7a27add453aa1a4f4f58',
    localFolder: 'dist/',
    includeSubFolders: true,
    createNewFileVersions: false,
    createdFolderSettings: {
      'dist/master': { // Regex match
        cacheMaxAge: 64800
      },
      'dist/dev': {  // Regex match
        cacheMaxAge: 2
      }
    },
    createdFileHeaders: {
      'dist/master/service-worker.js': { // Regex match
        'Service-Worker-Allowed': '/'
      }
    }
  }]
}).then(function (res) {
  console.log(res.length + 'files uploaded');
})

studioHelper.createDirectoryFolders(folderData) ⇒ Array.<ResultObj>

Create folders found in local directory if not already created

Kind: instance method of StudioHelper
Returns: Array.<ResultObj> - ResultObj.result

Param Type Default Description
folderData Object
folderData.folderId string Studio folder id
folderData.localFolder string Local folder path
[folderData.includeSubFolders] boolean false Create sub folders
[folderData.cache] boolean true Cache results
[folderData.logCreated] boolean false Log successfully created folders

studioHelper.getLocalFolders(path) ⇒ Array.<string>

Get local directory folders

Kind: instance method of StudioHelper
Returns: Array.<string> - folders

Param Type
path string

studioHelper.getFiles(folderId) ⇒ Promise.<Array.<Object>>

Get files of a folder

Kind: instance method of StudioHelper

Param Type Description
folderId string Studio folder id

studioHelper.deleteFiles(files, options) ⇒ Promise.<Object>

Delete files

Kind: instance method of StudioHelper

Param Type Default Description
files Array.<string> Array of file ids
options Object
[options.throttle] number 1 Number of concurrent delete file requests. Max 5
[options.showProgress] number false Number of concurrent delete file requests. Max 5
[options.progressOptions] ProgressOptions Progress bar options

studioHelper.uploadFiles(files, folderId) ⇒ Promise.<Array.<Object>>

Upload files to a specified folder

Kind: instance method of StudioHelper

Param Type Description
files Array.<string> file with path
folderId string Studio folder id

studioHelper.replaceFiles(files, [options]) ⇒ Promise.<Array.<Object>>

Replace files

Kind: instance method of StudioHelper

Param Type Default Description
files Array.<Object>
files[].fileId string Studio file id
files[].localFile string Local file path
[options] Object
[options.createNewVersion] boolean true Create new version of files

studioHelper.getFileHeaders(fileId) ⇒ ResultObj

Get file headers

Kind: instance method of StudioHelper

Param Type
fileId string

studioHelper.setFileHeaders(fileId, headerSettings, [options]) ⇒ ResultObj

Update file headers

Kind: instance method of StudioHelper

Param Type Default Description
fileId string
headerSettings FileHeaderSettings key / value pairs
[options] Object
[options.log] boolean false log results
[options.fileName] string "''" used for logging

studioHelper.getUploadInformation(files, folderId) ⇒ Array.<Object>

Get required information about files for upload

Kind: instance method of StudioHelper
Returns: Array.<Object> - Array of file information objects

Param Type Description
files Array.<string> files with paths
folderId string Studio folder id

studioHelper.getReplaceInformation(files, options)

Get required information about files for replacement

Kind: instance method of StudioHelper

Param Type Default Description
files Array.<Object>
files[].fileId string Studio file id
files[].localFile string Local file path
options Object
[options.createNewVersion] boolean true Create new version of files

studioHelper.getFolders([parentId]) ⇒ Promise.<Object>

Get folders

Kind: instance method of StudioHelper

Param Type Description
[parentId] string Parent folder id

studioHelper.createFolder(settings) ⇒ ResultObj

Create folder

Kind: instance method of StudioHelper
Returns: ResultObj - ResultObj.result

Param Type Default Description
settings Object
settings.name string Name of the new folder
[settings.parentId] string Studio folder in which we want to create the new folder
[settings.addIfExists] boolean true Return the already created folder id if false
[settings.localFolder] string local folder path
[settings.logCreated] boolean false log created folders
[settings.folderSettings] FolderUpdateSettings folder settings to apply after creation

studioHelper.deleteFolder(folderId) ⇒ Promise.<Object>

Delete folder

Kind: instance method of StudioHelper

Param Type
folderId string

studioHelper.deleteChildFolders(folderId) ⇒ Promise.<Object>

Delete child folders of a given folder

Kind: instance method of StudioHelper

Param Type
folderId string

studioHelper.getFolderSettings(folderId) ⇒ ResultObj

Get folder settings

Kind: instance method of StudioHelper
Returns: ResultObj - ResultObj.result

Param Type
folderId string

studioHelper.updateFolderSettings(folderId, folderSettings, [options]) ⇒ ResultObj

Update folder settings

Kind: instance method of StudioHelper

Param Type Default Description
folderId string
folderSettings FolderUpdateSettings settings
[options] Object
[options.log] boolean false log results
[options.folderName] string "''" used for logging

studioHelper.batchUpload(files) ⇒ Array.<object>

Batch upload/replace files

Kind: instance method of StudioHelper
Returns: Array.<object> - result

Param Type
files Array.<object>

ApiResponse : Object

Kind: global typedef
Properties

Name Type Description
status string "ok" or "error"
code number 0 for success
result T Results

ResultObj : Object

Kind: global typedef
Properties

Name Type Description
status string "ok" or "error"
code number 0 for success
result string | Object | Array | boolean Results

ProgressOptions

Kind: global typedef

Param Type
title string
total number
options ProgressOptions

Properties

Name Type
complete string
incomplete string
width number
clear boolean
total number

FileHeaderSettings : Object

Key / value pairs of wanted header names and their values

Kind: global typedef

CreateFolderResult : Object

Kind: global typedef
Properties

Name Type Description
id string Created folder id
name string Local folder name, might be different in Studio
localFolder string Local folder path

FolderSettings : Object

Kind: global typedef
Properties

Name Type Description
fileCacheMaxAge number Cache time in seconds
fileCacheProtected boolean Can cache time be changed
apiFolder boolean API folders can not be modified in Studio GUI
noversioning boolean
public boolean Public folder

FolderUpdateSettings : Object

Kind: global typedef
Properties

Name Type Description
fileCacheMaxAge number Cache time in seconds
fileCacheProtected number Can cache time be changed (0 or 1)
apiFolder number API folders can not be modified in Studio GUI (0 or 1)
noversioning number (0 or 1)
public number Public folder

About

Crasman Studio API Helper

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •