Skip to content

Commit af84a83

Browse files
committed
refactor(qseow): Enhance documentation and improve function signatures
1 parent 58e7a7b commit af84a83

20 files changed

+332
-80
lines changed

src/lib/browser/browser-install.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const { getMostRecentUsableChromeBuildId } = require('./browser-list-available')
2929
* @throws {Error} - If error getting browser cache path
3030
* @throws {Error} - If error getting browser executable path
3131
*/
32-
// eslint-disable-next-line no-unused-vars
3332
const browserInstall = async (options, _command) => {
3433
try {
3534
if (!options.browser || !options.browserVersion) {

src/lib/browser/browser-installed.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ const { homedir } = require('os');
44

55
const { logger, setLoggingLevel, bsiExecutablePath, isPkg } = require('../../globals');
66

7-
// Function to list all installed browsers
8-
// Returns an array of installed browsers
7+
/**
8+
* List all installed browsers.
9+
*
10+
* @param {object} options - An options object.
11+
* @param {string} [options.loglevel] - The log level. Can be one of "error", "warn", "info", "verbose", "debug", "silly". Default is "info".
12+
*
13+
* @returns {Promise<Array<Object>>} - A promise that resolves to an array of installed browsers.
14+
* Each browser is represented by an object with the following properties:
15+
* - browser {string}: The browser name, e.g. "chrome" or "firefox".
16+
* - buildId {string}: The build id, e.g. "121.0.6167.85".
17+
* - platform {string}: The platform, e.g. "win64" or "linux".
18+
* - path {string}: The path to the browser executable.
19+
*/
920
async function browserInstalled(options) {
1021
try {
1122
// Set log level

src/lib/browser/browser-list-available.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ const axios = require('axios');
66
const { logger, setLoggingLevel, bsiExecutablePath, isPkg } = require('../../globals');
77

88
/**
9-
* Maps Puppeteer's platform values to the Chrome version history API platform values
10-
* @param {string} puppeteerPlatform - Platform value from detectBrowserPlatform()
11-
* @returns {string} - Platform value for Chrome version history API
9+
* Maps Puppeteer's platform values to corresponding Chrome version history API platform values.
10+
* Converts 'win' to 'win', 'mac' to 'mac', and 'linux' to 'linux'.
11+
* If the platform cannot be mapped, it returns the original Puppeteer platform value.
12+
*
13+
* @param {string} puppeteerPlatform - Platform value from detectBrowserPlatform().
14+
* @returns {string} - Platform value suitable for the Chrome version history API.
1215
*/
1316
function mapPlatformToChrome(puppeteerPlatform) {
1417
// Chrome API expects: win, mac, linux
@@ -25,8 +28,20 @@ function mapPlatformToChrome(puppeteerPlatform) {
2528
return puppeteerPlatform;
2629
}
2730

28-
// Function to list all available browser versions
29-
// Returns an array of available browsers
31+
/**
32+
* List all available browser versions.
33+
*
34+
* @param {object} options - An options object.
35+
* @param {string} options.browser - Browser to list available versions for. Can be one of "chrome" or "firefox".
36+
* @param {string} options.channel - Which of the browser's release channel versions should be listed?
37+
* This option is only used for Chrome. Can be one of "stable", "beta", "dev", or "canary".
38+
* @param {string} options.loglevel - The log level. Can be one of "error", "warn", "info", "verbose", "debug", or "silly".
39+
*
40+
* @returns {Promise<Array<Object>>} - A promise that resolves to an array of available browsers.
41+
* Each browser is represented by an object with the following properties:
42+
* - version {string}: The browser version, e.g. "115.0.5790.90".
43+
* - name {string}: The browser name, e.g. "chrome/platforms/win/channels/stable/versions/115.0.5790.90".
44+
*/
3045
async function browserListAvailable(options) {
3146
try {
3247
// Set log level
@@ -212,8 +227,14 @@ async function browserListAvailable(options) {
212227
throw err;
213228
}
214229
}
215-
// Function to find most recent version of Chrome that Puppeteer can download and use
216-
// Returns the version number
230+
231+
/**
232+
* Finds the most recent version of Chrome that Puppeteer can download and use.
233+
*
234+
* @param {string} channel - The Chrome release channel.
235+
* Valid values are "stable", "beta", "dev", "canary".
236+
* @returns {Promise<string>} - A promise that resolves to the most recent usable Chrome build ID.
237+
*/
217238
async function getMostRecentUsableChromeBuildId(channel) {
218239
try {
219240
logger.verbose(`Get most recent usable Chrome build ID: Channel "${channel}"`);

src/lib/browser/browser-uninstall.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@ const fs = require('fs-extra');
55

66
const { logger, setLoggingLevel, bsiExecutablePath, isPkg } = require('../../globals');
77

8-
// Function to delete a specific browser
8+
/**
9+
* Uninstall a browser from the Butler Sheet Icons cache.
10+
* @param {object} options - An options object.
11+
* @param {string} options.browser - The browser to uninstall.
12+
* @param {string} options.browserVersion - The version of the browser to uninstall.
13+
* @param {string} [options.loglevel] - The log level. Can be one of "error", "warn", "info", "verbose", "debug", "silly". Default is "info".
14+
*
15+
* @returns {Promise<boolean>} - A promise that resolves to true if the browser was uninstalled successfully, false otherwise.
16+
*
17+
* @throws {Error} - If the browser was not found.
18+
* @throws {Error} - If there was an error uninstalling the browser.
19+
*/
920
const browserUninstall = async (options) => {
1021
try {
1122
// Set log level
@@ -62,7 +73,16 @@ const browserUninstall = async (options) => {
6273
}
6374
};
6475

65-
// Function to delete all browsers
76+
/**
77+
* Uninstall all browsers from the Butler Sheet Icons cache.
78+
*
79+
* @param {object} options - An options object.
80+
* @param {string} [options.loglevel] - The log level. Can be one of "error", "warn", "info", "verbose", "debug", "silly". Default is "info".
81+
*
82+
* @returns {Promise<boolean>} - A promise that resolves to true when all browsers are uninstalled.
83+
*
84+
* @throws {Error} - If there is an error during the uninstallation process.
85+
*/
6686
const browserUninstallAll = async (options) => {
6787
try {
6888
// Set log level

src/lib/cloud/cloud-collections.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ const QlikSaas = require('./cloud-repo');
77
const { qscloudTestConnection } = require('./cloud-test-connection');
88

99
/**
10+
* Lists all available collections in the Qlik Sense Cloud tenant.
1011
*
11-
* @param {*} options
12-
* @returns
12+
* @param {Object} options - Configuration options for listing collections.
13+
* @param {string} options.tenanturl - URL or host of Qlik Sense cloud tenant.
14+
* @param {string} options.apikey - API key used to access the Sense APIs.
15+
* @param {string} options.outputformat - Output format, either 'table' or 'json'.
16+
* @param {string} [options.loglevel] - Optional log level.
17+
*
18+
* @returns {Promise<boolean>} - Resolves to true if collections are successfully listed, false otherwise.
19+
*
20+
* @throws {Error} - Throws an error if there is an issue during the listing process.
1321
*/
22+
1423
const qscloudListCollections = async (options) => {
1524
try {
1625
// Set log level
@@ -135,6 +144,18 @@ const qscloudListCollections = async (options) => {
135144
}
136145
};
137146

147+
/**
148+
* Checks if a specified QS Cloud collection already exists.
149+
*
150+
* @param {object} options - Configuration options for the verification.
151+
* @param {string} options.tenanturl - URL of the QS Cloud tenant.
152+
* @param {string} options.apikey - API key for the QS Cloud tenant.
153+
* @param {string} options.collectionid - ID of the collection to check for existence.
154+
*
155+
* @returns {Promise<boolean>} - Resolves to true if the collection exists, false otherwise.
156+
*
157+
* @throws {Error} - Throws an error if there is an issue during the verification process.
158+
*/
138159
const qscloudVerifyCollectionExists = async (options) => {
139160
try {
140161
logger.debug('Checking if QS Cloud collection already exists');
@@ -149,13 +170,7 @@ const qscloudVerifyCollectionExists = async (options) => {
149170

150171
// Get all available collections
151172
const allCollections = await saasInstance.Get('collections');
152-
logger.debug(
153-
`COLLECTION EXISTS: Collections:\n${JSON.stringify(
154-
allCollections,
155-
null,
156-
2
157-
)}`
158-
);
173+
logger.debug(`COLLECTION EXISTS: Collections:\n${JSON.stringify(allCollections, null, 2)}`);
159174

160175
// Get index of specified collection among the existing ones.
161176
const index = allCollections.map((e) => e.id).indexOf(options.collectionid);

src/lib/cloud/cloud-create-thumbnails.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ const selectorLoginPageUserPwd = '[id="\u0031-password"]';
2323
const selectorLoginPageLoginButton = '[id="\u0031-submit"]';
2424

2525
/**
26+
* Process a single Qlik Sense Cloud app.
2627
*
27-
* @param {*} appId
28-
* @param {*} saasInstance
29-
* @param {*} options
28+
* @param {string} appId App ID of the app to process.
29+
* @param {QlikSaas} saasInstance QlikSaas object.
30+
* @param {Object} options Options object.
31+
*
32+
* @returns {Promise<void>}
3033
*/
3134
const processCloudApp = async (appId, saasInstance, options) => {
3235
// Create image directory on disk for this app
@@ -584,9 +587,27 @@ const processCloudApp = async (appId, saasInstance, options) => {
584587
};
585588

586589
/**
590+
* Create thumbnails for Qlik Sense Cloud (QSC)
591+
* @param {object} options - Object containing options for creating thumbnails
592+
* @param {string} options.tenanturl - URL of Qlik Sense Cloud tenant
593+
* @param {string} options.apikey - API key for Qlik Sense Cloud tenant
594+
* @param {string} options.loglevel - log level for the operation
595+
* @param {string} options.logonuserid - user ID for Qlik Sense Cloud tenant
596+
* @param {string} options.logonpwd - password for Qlik Sense Cloud tenant
597+
* @param {string} options.collectionid - ID of collection in Qlik Sense Cloud tenant
598+
* @param {string} options.appid - ID of app in Qlik Sense Cloud tenant
599+
* @param {string} options.imagedir - directory where images will be stored
600+
* @param {string} options.includesheetpart - optional parameter to include sheet parts in the thumbnails. Values: 1, 2, 4
601+
* @param {string} options.schemaversion - version of the QS schema
602+
* @param {string} options.appid - ID of app in Qlik Sense Cloud tenant
603+
* @param {string} options.browser - name of browser to use for rendering thumbnails
604+
* @param {string} options.browserVersion - version of browser to use for rendering thumbnails
605+
* @param {string} options.blurSheetStatus - which sheet statuses should be blurred
606+
* @param {string} options.blurSheetTag - which sheet tags should be blurred
607+
* @param {string} options.blurSheetNumber - number of sheets to blur
608+
* @param {string} options.blurFactor - blur factor
587609
*
588-
* @param {*} options
589-
* @returns
610+
* @returns {Promise<boolean>} - true if thumbnails were created successfully, false otherwise
590611
*/
591612
const qscloudCreateThumbnails = async (options) => {
592613
try {

src/lib/cloud/cloud-enigma.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ const WebSocket = require('ws');
55
const { logger } = require('../../globals');
66

77
/**
8+
* Sets up an Enigma connection to a Qlik Sense SaaS tenant.
89
*
9-
* @param {*} appId
10-
* @param {*} options
11-
* @param {*} command
12-
* @returns
10+
* @param {string} appId - The ID of the Qlik Sense app to connect to.
11+
* @param {Object} options - Options for the Enigma connection.
12+
* @param {string} options.schemaversion - The version of the Enigma schema to use.
13+
* @param {string} options.tenanturl - The URL of the Qlik Sense SaaS tenant.
14+
* @param {string} options.apikey - The API key to use for authentication.
15+
* @param {Object} command - Command options, used for logging.
16+
*
17+
* @returns {Object} An object with properties `schema` and `url` to be used when creating an Enigma session.
1318
*/
14-
// eslint-disable-next-line no-unused-vars
1519
const setupEnigmaConnection = (appId, options, command) => {
1620
logger.debug(`Prepping for cloud Enigma connection for app ${appId}`);
1721

src/lib/cloud/cloud-remove-sheet-icons.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ const QlikSaas = require('./cloud-repo');
88
const { qscloudTestConnection } = require('./cloud-test-connection');
99

1010
/**
11+
* Removes all sheet icons from a Qlik Sense Cloud app.
1112
*
12-
* @param {*} appId
13-
* @param {*} saasInstance
14-
* @param {*} options
13+
* @param {string} appId - The ID of the Qlik Sense Cloud app to process.
14+
* @param {Object} saasInstance - Instance of the QlikSaas class.
15+
* @param {Object} options - Configuration options for processing the app.
16+
* @param {string} options.tenanturl - Host address of the Qlik Sense Cloud tenant.
17+
* @param {string} options.apikey - API key for the Qlik Sense Cloud tenant.
18+
* @param {string} options.loglevel - The level of logging to output. Valid values are 'error', 'warn', 'info', 'verbose', 'debug', 'silly'.
19+
*
20+
* @returns {Promise<void>}
1521
*/
1622
const removeSheetIconsCloudApp = async (appId, saasInstance, options) => {
1723
try {
@@ -147,9 +153,16 @@ const removeSheetIconsCloudApp = async (appId, saasInstance, options) => {
147153
};
148154

149155
/**
156+
* Removes all sheet icons from one or more Qlik Sense Cloud applications.
157+
*
158+
* @param {Object} options - Configuration options for the command.
159+
* @param {string} options.tenanturl - URL or host of Qlik Sense cloud tenant. Example: "https://tenant.eu.qlikcloud.com" or "tenant.eu.qlikcloud.com"
160+
* @param {string} options.apikey - API key used to access the Sense APIs
161+
* @param {string} options.appid - The ID of the Qlik Sense Cloud application to process.
162+
* @param {string} options.collectionid - The ID of the collection containing apps to process.
163+
* @param {string} options.loglevel - The level of logging to output. Valid values are 'error', 'warn', 'info', 'verbose', 'debug', 'silly'.
150164
*
151-
* @param {*} options
152-
* @returns
165+
* @returns {Promise<boolean>} - true if thumbnails were removed successfully, false otherwise.
153166
*/
154167
const qscloudRemoveSheetIcons = async (options) => {
155168
try {

src/lib/cloud/cloud-repo-request.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ axios.interceptors.response.use(
3131
})
3232
);
3333

34+
/**
35+
* Takes a Buffer and returns a Readable Stream
36+
*
37+
* @param {Buffer} buffer The buffer to stream
38+
*
39+
* @returns {Readable} A Readable Stream
40+
*/
3441
function bufferToStream(buffer) {
3542
const stream = new Readable();
3643
stream.push(buffer);
@@ -39,6 +46,14 @@ function bufferToStream(buffer) {
3946
return stream;
4047
}
4148

49+
/**
50+
* Makes a request to the Qlik Cloud Repository API.
51+
*
52+
* @param {object} config Axios config object
53+
* @param {array} [data=[]] Accumulated data from previous paginated requests
54+
*
55+
* @returns {Promise<object|array>} The response data
56+
*/
4257
async function makeRequest(config, data = []) {
4358
let returnData = [...data];
4459

@@ -82,6 +97,19 @@ async function makeRequest(config, data = []) {
8297
return returnData;
8398
}
8499

100+
/**
101+
* Makes a request to the Qlik Cloud Repository API.
102+
*
103+
* @param {object} mainConfig Configuration object for Qlik Cloud
104+
* @param {string} path Path to make the request to
105+
* @param {string} type HTTP method to use
106+
* @param {object|Buffer} data Data to send with the request
107+
* @param {string} [contentType=application/json] Content-Type of the request
108+
* @param {Buffer} [file] File to send with the request
109+
* @param {string} [fileName] Name of the file
110+
*
111+
* @returns {Promise<object|array>} The response data
112+
*/
85113
module.exports = async (
86114
mainConfig,
87115
path,

src/lib/cloud/cloud-repo.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22
/* eslint-disable no-param-reassign */
33
const request = require('./cloud-repo-request');
44

5+
/**
6+
* Initializes a QlikSaas instance for interacting with a Qlik SaaS environment.
7+
*
8+
* @param {Object} config - Configuration object.
9+
* @param {string} config.url - The base URL of the Qlik SaaS environment. Must include protocol.
10+
* @param {string} config.token - API token for authentication.
11+
* @param {number} [config.version=1] - Optional API version, defaults to 1 if not provided.
12+
*
13+
* @throws Will throw an error if the URL or API token is not provided.
14+
*
15+
* @property {function} Get - Makes a GET request to the specified path.
16+
* @property {function} Delete - Makes a DELETE request to the specified path.
17+
* @property {function} Patch - Makes a PATCH request with the provided data or file.
18+
* @property {function} Post - Makes a POST request with the provided data or file.
19+
* @property {function} Put - Makes a PUT request with the provided data or file.
20+
*/
521
const qlikSaas = function QlikSaas(config) {
622
if (!config.url) throw Error({ message: 'URL parameter is required' });
723
if (!config.token) throw Error({ message: 'API token parameter is required' });

0 commit comments

Comments
 (0)