@sisense/sdk-cli 0.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,35 @@
1
+ # SISENSE COMPOSE SDK
2
+
3
+ # END USER LICENSE AGREEMENT
4
+
5
+ THIS END USER LICENSE AGREEMENT (“EULA”) FORMS A BINDING AGREEMENT BETWEEN YOU INDIVIDUALLY OR THE ENTITY ON WHOSE BEHALF YOU ARE ACCEPTING THIS AGREEMENT (“YOU”) AND DESCRIBES THE TERMS AND CONDITIONS GOVERNING THE USE OF ANY APPLICATION PROGRAMMING INTERFACE, SOFTWARE DEVELOPMENT KIT, CODE SNIPPET, SAMPLE CODE, USER INTERFACE COMPONENT, VISUALIZATION, CLI TOOLS, OR SAMPLE DATA, AND THE CORRESPONDING DOCUMENTATION FOR EACH, ANY UPDATES AND UPGRADES THERETO, AND ANY MODIFICATIONS, ENHANCEMENTS, OR IMPROVEMENTS, OF ANY OF THE FOREGOING (EACH, A “TOOL” AND COLLECTIVELY, THE “TOOLS”), MADE AVAILABLE BY SISENSE LTD. OR ITS AFFILIATES (“SISENSE”).
6
+
7
+ 1. ACCEPTANCE. By downloading, importing, installing and/or using any Tool (or any portion thereof), You represent and warrant that: (a) You have read, understand and accept all of the provisions of this EULA; and (b) if You are accepting on behalf of an entity, You are an employee, contractor or agent of such entity and have the authority and all legal power to accept on behalf of such entity.
8
+
9
+ 2. LICENSE SCOPE. Subject to the terms and conditions of this EULA, Sisense hereby grants You a royalty-free, non-exclusive, non-transferrable, limited license to access, download and use the Tools (in the manner described in the documentation for such Tool) solely for utilization with Your use of the applicable Sisense subscription product (the “Product”), to which You must have purchased the necessary license and use rights pursuant to a separate written agreement with Sisense (the “Master Subscription Agreement”).
10
+
11
+ 3. RESTRICTIONS. You agree that You will not (and have no license to) and will not permit any third party to: (i) use the Tools except as permitted under this EULA; (ii) sell, resell, license, sublicense, rent, lease, encumber, lend, distribute, transfer, or provide a third party with access to the Tools; (iii) modify or create derivative works of the Tools; (iv) circumvent or remove by any means any copy protection used by Sisense in connection with the Tools; (v) use the Tools to develop a competitive product offering; (vi) use the Tool to access Sisense products in a manner not authorized by the Master Subscription Agreement or this EULA; or (vii) use the Tools in any manner that violates the Master Subscription Agreement or any applicable laws or regulations;
12
+
13
+ 4. SISENSE OWNERSHIP. Except for those portions licensed to Sisense by third parties, Sisense retains all right, title and interest in and to the Tools, including without limitation all copyrights and other intellectual property or other proprietary rights worldwide therein (including but not limited to all patent, trademark, service mark, copyright, trade secret, know-how, moral right, and any other intellectual and intangible property rights, including all continuations, continuations in part, applications, renewals, and extensions of any of the foregoing, whether registered or unregistered). All rights not expressly granted herein are reserved. You may not remove, delete or modify any of the Sisense copyright statements in the Tools.
14
+
15
+ 5. OPEN SOURCE COMPONENTS. To the extent any open source software components are provided with or used by the Tools, such components are licensed to You under the terms of the applicable license agreements included with such open source software components.
16
+
17
+ 6. THIRD-PARTY COMPONENTS. To the extent that any Tool includes one or more components licensed by a third-party (a “Component”), and such third-party’s license requirements apply to such Component in a Tool, such additional license terms will be provided in the open source disclosure file provided with or within a Tool download. Third-party license terms shall take precedence over this EULA to the extent that they impose additional restrictions or limitations on You than the license provided herein for download and use of a Component. You agree that: (a) to the extent that the terms between You and the third party for use of a third-party technology accessed by the Component are more restrictive, such terms shall apply to Your use of the Component; (b) Sisense, and not the third party, is responsible for the Component including, without limitation, for any warranties, maintenance, and support thereof, and the third party does not warrant the Component’s accuracy, reliability, completeness, usefulness, non-infringement, or quality of the Component, and will not be liable for any losses or damages of any kind, including lost profits or other indirect or consequential damages, relating to use of or reliance on the Component; and (c) the third party owns all right, title, and interest in and to the Component, including all intellectual property rights therein.
18
+
19
+ 7. TERM, TERMINATION, AND CHANGES. This EULA shall continue as long as You are in compliance with the terms specified herein or until otherwise terminated. This EULA shall automatically terminate upon the expiration or termination of the Master Subscription Agreement. You agree, upon termination, to destroy all copies of the Tools within Your possession or control. The Disclaimer of Warranties, Limitation of Liability and Indemnification sections set out in this EULA shall survive any termination or expiration of this EULA. Sisense may, in its sole discretion, update this EULA from time to time.
20
+
21
+ 8. NO DUTY TO SUPPORT. You expressly acknowledge that Sisense has no duty or obligation to support the Tools, or to provide updates or bug fixes to the Tools.
22
+
23
+ 9. DISCLAIMER OF WARRANTIES. THE TOOLS ARE PROVIDED “AS IS” WITHOUT ANY WARRANTIES OF ANY KIND. TO THE MAXIMUM EXTENT PERMITTED BY LAW, SISENSE DISCLAIMS RESPONSIBILITY FOR ANY HARM RESULTING FROM YOUR USE OF ANY TOOL. SISENSE DISCLAIMS TO THE FULLEST EXTENT PERMITTED, ALL GUARANTEES AND EXPRESS, IMPLIED AND STATUTORY WARRANTIES, INCLUDING WITHOUT LIMITATION THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT OF PROPRIETARY RIGHTS, AND ANY WARRANTIES REGARDING THE AVAILABILITY, SECURITY, RELIABILITY, TIMELINESS AND PERFORMANCE OF ANY TOOL. YOU ACKNOWLEDGE THAT YOU DOWNLOAD AND USE THE TOOLS AT YOUR OWN DISCRETION AND RISK, AND YOU ARE SOLELY RESPONSIBLE FOR ANY DAMAGES TO HARDWARE DEVICES OR LOSS OF DATA THAT RESULT FROM THE DOWNLOAD OR USE OF ANY TOOL.
24
+
25
+ 10. LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT WILL SISENSE BE LIABLE FOR ANY LOST PROFITS OR BUSINESS OPPORTUNITIES, LOSS OF USE, BUSINESS INTERRUPTION, LOSS OF DATA, OR ANY OTHER INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR FROM LIBRARY OR YOUR USE OF THE TOOLS, UNDER ANY THEORY OF LIABILITY, WHETHER BASED IN CONTRACT, TORT, NEGLIGENCE, PRODUCT LIABILITY, OR OTHERWISE. TO THE EXTENT THE PRECEDING LIMITATION DOES NOT APPLY UNDER APPLICABLE LAW, SISENSE’S LIABILITY ARISING OUT OF THE TOOLS PROVIDED HEREUNDER SHALL NOT, IN ANY EVENT, EXCEED USD $100.00.
26
+
27
+ THE FOREGOING LIMITATIONS SHALL APPLY TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, REGARDLESS OF WHETHER A PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND REGARDLESS OF WHETHER ANY REMEDY FAILS OF ITS ESSENTIAL PURPOSE.
28
+
29
+ 11. INDEMNIFICATION. You agree to defend, indemnify and hold harmless Sisense, and any of its directors, officers, employees, affiliates, subsidiaries or agents, from and against any and all claims, losses, damages, liabilities and other expenses (including reasonable attorneys' fees), arising from or related to: (i) Your use of the Tools; (ii) any derivative works You create using the Tools; and (iii) Your breach of this EULA.
30
+
31
+ 12. EXPORT CONTROL. The Tools are provided subject to the U.S. Export Administration Regulations and the regulations of other jurisdictions (e.g., the European Union). Diversion contrary to applicable law is prohibited. Without limiting the foregoing, You agree that (i) You are not acting on behalf of any person who is a citizen, national, or resident of, or who is controlled by the government of any country to which the United States or other applicable government body has prohibited export transactions; (ii) You are not acting on behalf of, any person or entity listed on a relevant list of persons to whom export is prohibited (e.g., the U.S. Treasury Department list of Specially Designated Nationals and Blocked Persons, the U.S. Commerce Department Denied Persons List or Entity List, etc.); and (iii) You will not use the Tools for any purpose prohibited by applicable law.
32
+
33
+ 13. GOVERNMENT USE. If a Tool provided under the Master Subscription Agreement is software, then it is commercial computer software developed exclusively at private expense. Unless otherwise set forth in the Master Subscription Agreement, use, duplication, and disclosure by civilian agencies of the U.S. Government will not exceed those minimum rights set forth in FAR 52.227-19(c) or successor regulations. Use, duplication, and disclosure by U.S. Department of Defense agencies is subject solely to the license terms contained in this EULA, as stated in DFARS 227.7202 or successor regulations. U.S. Government rights will apply only to the specific agency and program for which the Product is obtained.
34
+
35
+ 14. GOVERNING LAW; ENTIRE AGREEMENT. This EULA shall be governed by the laws of the State of New York and the United States of America without regard to conflict of laws principles. You may not assign any part of this EULA without the prior written consent of Sisense. Any attempted assignment without consent shall be void. This EULA represents the entire agreement between You and Sisense with respect to the Tools and supersedes all prior written or oral communications, understandings and agreements containing the subject matter contained herein. Any waiver of these terms must be in writing to be effective. If any provision of these terms is found to be invalid or unenforceable, the remaining terms will continue to be valid and enforceable to the fullest extent permitted by law. In the event of a conflict between this EULA and the Master Subscription Agreement, the terms of this EULA will prevail to the extent applicable to the license and use of the Tools.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ This library, which is a part of Sisense Compose SDK,
2
+ provides a set of command line utilities.
3
+ One of which is to generate TypeScript representation of a Sisense data model.
4
+
5
+ ## Installation
6
+
7
+ Install the package as a dev dependency in your project.
8
+
9
+ With npm:
10
+
11
+ ```sh
12
+ npm i @sisense/sdk-cli --save-dev
13
+ ```
14
+
15
+ With Yarn:
16
+
17
+ ```sh
18
+ yarn add @sisense/sdk-cli --dev
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Run the following command to create a `my-data-source.ts` file that contains a TypeScript representation of your data model.
24
+ Substitute `<username>`, `<instance url>`, `<data source name>` with the values for your instance.
25
+
26
+ With npm:
27
+
28
+ ```sh
29
+ npx sdk-cli get-data-model --username "<username>" --output my-data-source.ts --dataSource "<data source name>" --url <instance url>
30
+ ```
31
+
32
+ With Yarn:
33
+
34
+ ```sh
35
+ yarn run sdk-cli get-data-model --username "<username>" --output my-data-source.ts --dataSource "<data source name>" --url <instance url>
36
+ ```
37
+
38
+ You will be prompted for the password.
39
+
40
+ The resulting file is created in the current directory.
41
+
42
+ Instead of `--username "<username>"`, you can also use `--token <token>` to authenticate with [an API token](https://sisense.dev/guides/restApi/using-rest-api.html).
43
+ Substitute `<token>`, `<instance url>`, `<data source name>` with the values for your instance.
44
+
45
+ With npm:
46
+
47
+ ```sh
48
+ npx sdk-cli get-data-model --token <token> --output my-data-source.ts --dataSource "<data source name>" --url <instance url>
49
+ ```
50
+
51
+ With Yarn:
52
+
53
+ ```sh
54
+ yarn run sdk-cli get-data-model --token <token> --output my-data-source.ts --dataSource "<data source name>" --url <instance url>
55
+ ```
56
+
57
+ Or use `--wat <wat>` to authenticate with a [Web Access Token (WAT)](https://docs.sisense.com/main/SisenseLinux/using-web-access-token.htm).
58
+ Substitute `<token>`, `<instance url>`, `<data source name>` with the values for your instance.
59
+
60
+ With npm:
61
+
62
+ ```sh
63
+ npx sdk-cli get-data-model --wat <wat> --output my-data-source.ts --dataSource "<data source name>" --url <instance url>
64
+ ```
65
+
66
+ With Yarn:
67
+
68
+ ```sh
69
+ yarn run sdk-cli get-data-model --wat <wat> --output my-data-source.ts --dataSource "<data source name>" --url <instance url>
70
+ ```
@@ -0,0 +1,3 @@
1
+ import { CommandModule } from 'yargs';
2
+ import { GetApiTokenOptions } from '../types.js';
3
+ export declare const getApiTokenCommand: CommandModule<unknown, GetApiTokenOptions>;
@@ -0,0 +1,51 @@
1
+ import { getHttpClient, handleHttpClientLogin } from './helpers.js';
2
+ import { promptPasswordInteractive } from './prompts.js';
3
+ import { trackExecution } from '../tracking.js';
4
+ const command = 'get-api-token';
5
+ const describe = 'Get an API token from the given Sisense URL using the provided credentials.';
6
+ const builder = (yargs) => yargs
7
+ .options({
8
+ username: {
9
+ type: 'string',
10
+ describe: 'Specify the username for username/password authentication',
11
+ alias: ['u'],
12
+ demandOption: true,
13
+ },
14
+ password: {
15
+ type: 'string',
16
+ describe: 'Specify the password for username/password authentication. If not provided, the program will prompt for it interactively.',
17
+ alias: ['p'],
18
+ },
19
+ url: {
20
+ type: 'string',
21
+ describe: 'Specify the Sisense URL to connect to',
22
+ demandOption: true,
23
+ },
24
+ })
25
+ .example([['$0 get-api-token --url https://domain.sisense.com -u user@domain.com']]);
26
+ const handler = async (options) => {
27
+ const { url, username } = options;
28
+ let { password } = options;
29
+ if (username && !password) {
30
+ ({ maskedPassword: password } = await promptPasswordInteractive(username));
31
+ }
32
+ const httpClient = getHttpClient(url, username, password);
33
+ try {
34
+ await handleHttpClientLogin(httpClient);
35
+ trackExecution(httpClient, command, options);
36
+ const response = await httpClient.get('/api/v1/authentication/tokens/api');
37
+ console.log(response);
38
+ }
39
+ catch (err) {
40
+ if (err)
41
+ console.log(err);
42
+ // exit code 1: One or more generic errors encountered upon exit
43
+ process.exit(1);
44
+ }
45
+ };
46
+ export const getApiTokenCommand = {
47
+ command,
48
+ describe,
49
+ builder,
50
+ handler,
51
+ };
@@ -0,0 +1,4 @@
1
+ import { Arguments, CommandModule } from 'yargs';
2
+ import { Command, GetDataModelOptions } from '../types.js';
3
+ export declare const getDataModel: (options: Arguments<GetDataModelOptions>, commandName: Command) => Promise<void>;
4
+ export declare const getDataModelCommand: CommandModule<unknown, GetDataModelOptions>;
@@ -0,0 +1,94 @@
1
+ import { getHttpClient, createDataModel, writeFile, handleHttpClientLogin, getFilePathInfo, isSupportedOutputFile, } from './helpers.js';
2
+ import { promptPasswordInteractive } from './prompts.js';
3
+ import { trackExecution } from '../tracking.js';
4
+ const command = 'get-data-model';
5
+ const describe = 'Write the TypeScript or JavaScript representation of a data model from the given Sisense URL and data source';
6
+ const builder = (yargs) => yargs
7
+ .options({
8
+ username: {
9
+ type: 'string',
10
+ describe: 'Specify the username for username/password authentication',
11
+ alias: ['u'],
12
+ },
13
+ password: {
14
+ type: 'string',
15
+ describe: 'Specify the password for username/password authentication. If not provided, the program will prompt for it interactively.',
16
+ alias: ['p'],
17
+ },
18
+ token: {
19
+ type: 'string',
20
+ describe: 'Specify bearer token for token based authentication',
21
+ },
22
+ wat: {
23
+ type: 'string',
24
+ describe: 'Specify web access token for token based authentication',
25
+ },
26
+ output: {
27
+ type: 'string',
28
+ describe: 'Specify the output TypeScript (.ts) or JavaScript (.js) filename',
29
+ alias: ['o'],
30
+ },
31
+ url: {
32
+ type: 'string',
33
+ describe: 'Specify the Sisense URL to connect to',
34
+ demandOption: true,
35
+ },
36
+ dataSource: {
37
+ type: 'string',
38
+ alias: ['d'],
39
+ describe: 'Specify the data source name',
40
+ demandOption: true,
41
+ },
42
+ })
43
+ .example([
44
+ [
45
+ '$0 get-data-model --url https://domain.sisense.com -u user@domain.com -d "Sample ECommerce" -o MySampleEComm.ts',
46
+ ],
47
+ ]);
48
+ export const getDataModel = async (options, commandName) => {
49
+ const { url, dataSource, username, token, wat, output } = options;
50
+ let { password } = options;
51
+ // validate url
52
+ if (!/^(http|https):\/\//.test(url)) {
53
+ console.log(`Error connecting to ${url}`);
54
+ console.log('ValidationError: URL must start with http:// or https://');
55
+ // exit code 2: Incorrect usage, such as invalid options or missing arguments
56
+ process.exit(2);
57
+ }
58
+ //validate output file path
59
+ const outputInfo = getFilePathInfo({
60
+ filePath: output,
61
+ defaultBaseName: dataSource,
62
+ defaultFileExtension: '.ts',
63
+ });
64
+ if (!isSupportedOutputFile(outputInfo)) {
65
+ console.log(`Invalid output file extension: ${outputInfo.extension}. Only TypeScript (.ts) or JavaScript (.js) file is supported.`);
66
+ // exit code 2: Incorrect usage, such as invalid options or missing arguments
67
+ process.exit(2);
68
+ }
69
+ // if username is provided but password is not, prompt for password interactively
70
+ if (username && !password) {
71
+ ({ maskedPassword: password } = await promptPasswordInteractive(username));
72
+ }
73
+ const httpClient = getHttpClient(url, username, password, token, wat);
74
+ try {
75
+ await handleHttpClientLogin(httpClient);
76
+ trackExecution(httpClient, commandName, options);
77
+ await createDataModel(httpClient, dataSource).then((model) => {
78
+ return writeFile(model, outputInfo);
79
+ });
80
+ }
81
+ catch (err) {
82
+ if (err)
83
+ console.log(err);
84
+ // exit code 1: One or more generic errors encountered upon exit
85
+ process.exit(1);
86
+ }
87
+ };
88
+ const handler = (options) => getDataModel(options, 'get-data-model');
89
+ export const getDataModelCommand = {
90
+ command,
91
+ describe,
92
+ builder,
93
+ handler,
94
+ };
@@ -0,0 +1,30 @@
1
+ import { HttpClient } from '@sisense/sdk-rest-client';
2
+ import { DataModel } from '@sisense/sdk-data';
3
+ declare function getHttpClient(url: string, username?: string, password?: string, token?: string, wat?: string): HttpClient;
4
+ export declare const handleHttpClientLogin: (httpClient: HttpClient) => Promise<void>;
5
+ /**
6
+ * Create a data model for a Sisense data source
7
+ */
8
+ declare function createDataModel(httpClient: HttpClient, dataSource: string): Promise<DataModel>;
9
+ declare function rewriteDataModel(dataModel: any): DataModel;
10
+ declare function writeFile(dataModel: DataModel, outputFilePathInfo: SupportedOutputFilePathInfo): Promise<void>;
11
+ export declare type FilePathInfo = {
12
+ dir: string;
13
+ baseName: string;
14
+ extension: string;
15
+ };
16
+ /**
17
+ * Gets the directory, base name, and extension of a file path.
18
+ * If the file path is not provided, the default values are used.
19
+ */
20
+ declare function getFilePathInfo({ filePath, defaultBaseName, defaultFileExtension, }: {
21
+ filePath?: string;
22
+ defaultFileExtension: SupportedOutputFileExtension;
23
+ defaultBaseName: string;
24
+ }): FilePathInfo;
25
+ export declare type SupportedOutputFileExtension = '.ts' | '.js';
26
+ export declare type SupportedOutputFilePathInfo = FilePathInfo & {
27
+ extension: SupportedOutputFileExtension;
28
+ };
29
+ declare function isSupportedOutputFile(filePathInfo: FilePathInfo): filePathInfo is SupportedOutputFilePathInfo;
30
+ export { getHttpClient, createDataModel, rewriteDataModel, writeFile, getFilePathInfo, isSupportedOutputFile, };
@@ -0,0 +1,166 @@
1
+ /* eslint-disable max-lines */
2
+ /* eslint-disable max-lines-per-function */
3
+ /* eslint-disable max-params */
4
+ /* eslint-disable @typescript-eslint/restrict-template-expressions */
5
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
6
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
7
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
8
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
9
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
10
+ import { HttpClient, getAuthenticator, WatAuthenticator, BearerAuthenticator, } from '@sisense/sdk-rest-client';
11
+ import { MetadataTypes } from '@sisense/sdk-data';
12
+ import { writeTypescript, writeJavascript } from '@sisense/sdk-modeling';
13
+ import path from 'path';
14
+ import { DimensionalQueryClient } from '@sisense/sdk-query-client';
15
+ import { PKG_VERSION } from '../package-version.js';
16
+ import { trackCliError } from '@sisense/sdk-common';
17
+ function getHttpClient(url, username, password, token, wat) {
18
+ const auth = getAuthenticator(url, username, password, token, wat, false);
19
+ if (!auth) {
20
+ throw new Error('Invalid authentication method');
21
+ }
22
+ return new HttpClient(url, auth, 'sdk-cli' + (PKG_VERSION ? `-${PKG_VERSION}` : ''));
23
+ }
24
+ export const handleHttpClientLogin = async (httpClient) => {
25
+ console.log('Logging in... ');
26
+ try {
27
+ const isLoggedIn = await httpClient.login();
28
+ if (!isLoggedIn) {
29
+ console.log(`Failed. ${httpClient.auth instanceof WatAuthenticator ||
30
+ httpClient.auth instanceof BearerAuthenticator
31
+ ? 'Double-check your token'
32
+ : 'Wrong credentials'}.\r\n`);
33
+ }
34
+ console.log('OK!\r\n');
35
+ }
36
+ catch (err) {
37
+ console.log(`Error connecting to ${httpClient.url}. \r\n${err}\r\n`);
38
+ return Promise.reject();
39
+ }
40
+ return Promise.resolve();
41
+ };
42
+ /**
43
+ * Create a data model for a Sisense data source
44
+ */
45
+ async function createDataModel(httpClient, dataSource) {
46
+ const queryClient = new DimensionalQueryClient(httpClient);
47
+ console.log('Getting fields... ');
48
+ try {
49
+ return await queryClient.getDataSourceFields(dataSource).then((fields) => {
50
+ console.log('OK!\r\n');
51
+ const dataModel = {
52
+ name: dataSource,
53
+ dataSource: dataSource,
54
+ metadata: fields,
55
+ };
56
+ return rewriteDataModel(dataModel);
57
+ });
58
+ }
59
+ catch (err) {
60
+ trackCliError({
61
+ packageVersion: PKG_VERSION,
62
+ component: 'createDataModel',
63
+ error: err,
64
+ }, httpClient).catch(() => { });
65
+ console.log(`Error fetching metadata. Reason: ${err}\r\n`);
66
+ return Promise.reject();
67
+ }
68
+ }
69
+ function rewriteDataModel(dataModel) {
70
+ console.log(`Cleaning metadata... `);
71
+ dataModel.metadata = dataModel.metadata
72
+ .filter((item) => !item.dimensionTable)
73
+ .map((item) => {
74
+ const result = {
75
+ name: item.title,
76
+ expression: item.id,
77
+ type: MetadataTypes.Dimension,
78
+ group: undefined,
79
+ };
80
+ result.group = item.table;
81
+ switch (item.dimtype) {
82
+ case 'text':
83
+ result.type = MetadataTypes.TextAttribute;
84
+ break;
85
+ case 'numeric':
86
+ result.type = MetadataTypes.NumericAttribute;
87
+ break;
88
+ case 'datetime':
89
+ result.type = MetadataTypes.DateDimension;
90
+ break;
91
+ }
92
+ return result;
93
+ });
94
+ console.log('OK!\r\n');
95
+ console.log(`Grouping metadata... `);
96
+ const grouped = dataModel.metadata.reduce((r, a) => {
97
+ if (!r[a.group]) {
98
+ r[a.group] = {
99
+ name: a.group,
100
+ type: MetadataTypes.Dimension,
101
+ dimensions: [],
102
+ attributes: [],
103
+ };
104
+ }
105
+ // If the field is date, model it as a date dimension
106
+ // otherwise, model the field as a dimension attribute.
107
+ if (a.type === MetadataTypes.DateDimension) {
108
+ r[a.group].dimensions.push(a);
109
+ }
110
+ else {
111
+ r[a.group].attributes.push(a);
112
+ }
113
+ delete a.group;
114
+ return r;
115
+ }, {});
116
+ dataModel.metadata = Object.values(grouped);
117
+ console.log('OK!\r\n');
118
+ return dataModel;
119
+ }
120
+ async function writeFile(dataModel, outputFilePathInfo) {
121
+ const { dir, baseName, extension } = outputFilePathInfo;
122
+ try {
123
+ console.log(`Writing '${getFullFilePath(outputFilePathInfo)}'...`);
124
+ if (extension === '.ts') {
125
+ await writeTypescript(dataModel, { filename: baseName, dir });
126
+ }
127
+ else if (extension === '.js') {
128
+ await writeJavascript(dataModel, { filename: baseName, dir });
129
+ // Currently, we don't allow writing JSON files. Can be uncommented in the future to enable supporting JSON.
130
+ // } else if (extension === '.json') {
131
+ // writeFileSync(outputFileName, JSON.stringify(dataModel, null, ' '), 'utf-8');
132
+ // }
133
+ }
134
+ console.log(`OK!\r\n`);
135
+ }
136
+ catch (err) {
137
+ console.log(`Error writing file. Reason: ${err}\r\n`);
138
+ throw err;
139
+ }
140
+ }
141
+ /**
142
+ * Gets the directory, base name, and extension of a file path.
143
+ * If the file path is not provided, the default values are used.
144
+ */
145
+ function getFilePathInfo({ filePath, defaultBaseName, defaultFileExtension, }) {
146
+ const dir = filePath ? path.dirname(filePath) : '.';
147
+ const extension = filePath ? getExtension(filePath, defaultFileExtension) : defaultFileExtension;
148
+ const baseName = filePath ? path.basename(filePath, extension) : defaultBaseName;
149
+ return { dir, baseName, extension };
150
+ }
151
+ function getExtension(filePath, defaultFileExtension) {
152
+ const extname = path.extname(filePath);
153
+ if (extname === '') {
154
+ return defaultFileExtension;
155
+ }
156
+ else {
157
+ return extname;
158
+ }
159
+ }
160
+ function getFullFilePath(filePathInfo) {
161
+ return path.join(filePathInfo.dir, filePathInfo.baseName + filePathInfo.extension);
162
+ }
163
+ function isSupportedOutputFile(filePathInfo) {
164
+ return ['.ts', '.js'].includes(filePathInfo.extension);
165
+ }
166
+ export { getHttpClient, createDataModel, rewriteDataModel, writeFile, getFilePathInfo, isSupportedOutputFile, };
@@ -0,0 +1,9 @@
1
+ import { ArgumentsCamelCase } from 'yargs';
2
+ import { GetDataModelOptions } from '../types.js';
3
+ export declare const handleHelper: (combinedAnswers: ArgumentsCamelCase<GetDataModelOptions>) => Promise<void>;
4
+ export declare const validateNotEmpty: (input: string) => Promise<true | "this field cannot be blank">;
5
+ export declare const interactiveCommand: {
6
+ command: "interactive";
7
+ desc: string;
8
+ handler: () => Promise<void>;
9
+ };
@@ -0,0 +1,52 @@
1
+ /* eslint-disable max-lines-per-function */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
4
+ /* eslint-disable @typescript-eslint/no-use-before-define */
5
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
6
+ /* eslint-disable @typescript-eslint/restrict-template-expressions */
7
+ /* eslint-disable @typescript-eslint/no-shadow */
8
+ /* eslint-disable @typescript-eslint/require-await */
9
+ /* eslint-disable max-lines */
10
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
11
+ import { getDataModel } from './get-data-model.js';
12
+ import { promptCommand, promptUrl, promptAuth, promptPasswordAuth, promptTokenAuth, promptWatAuth, promptDataModel, } from './prompts.js';
13
+ const command = 'interactive';
14
+ const desc = 'Run in interactive mode';
15
+ export const handleHelper = (combinedAnswers) => getDataModel(combinedAnswers, 'interactive');
16
+ const handler = async () => {
17
+ const cmd = await promptCommand();
18
+ if (cmd.command !== 'get-data-model')
19
+ return;
20
+ const urlInput = await promptUrl();
21
+ const url = `${urlInput.protocol}://${urlInput.hostname}:${urlInput.port}`;
22
+ console.log(`\nSisense host URL: ${url}\n`);
23
+ const auth = await promptAuth();
24
+ let passwordAuthAnswers, tokenAuthAnswers, watAuthAnswers;
25
+ if (auth.auth === 'password') {
26
+ passwordAuthAnswers = await promptPasswordAuth();
27
+ }
28
+ else if (auth.auth === 'token') {
29
+ tokenAuthAnswers = await promptTokenAuth();
30
+ }
31
+ else if (auth.auth === 'web access token') {
32
+ watAuthAnswers = await promptWatAuth();
33
+ }
34
+ const answers = await promptDataModel();
35
+ answers.url = url;
36
+ return handleHelper({
37
+ ...passwordAuthAnswers,
38
+ ...tokenAuthAnswers,
39
+ ...watAuthAnswers,
40
+ ...answers,
41
+ });
42
+ };
43
+ export const validateNotEmpty = async (input) => {
44
+ if (input === undefined || input.trim() === '')
45
+ return 'this field cannot be blank';
46
+ return true;
47
+ };
48
+ export const interactiveCommand = {
49
+ command,
50
+ desc,
51
+ handler,
52
+ };
@@ -0,0 +1,30 @@
1
+ import inquirer from 'inquirer';
2
+ import { ArgumentsCamelCase } from 'yargs';
3
+ export declare const promptPasswordInteractive: (username: string) => Promise<ArgumentsCamelCase<{
4
+ maskedPassword: string;
5
+ }>> & {
6
+ ui: inquirer.ui.Prompt<ArgumentsCamelCase<{
7
+ maskedPassword: string;
8
+ }>>;
9
+ };
10
+ export declare const promptCommand: () => Promise<any> & {
11
+ ui: inquirer.ui.Prompt<any>;
12
+ };
13
+ export declare const promptUrl: () => Promise<any> & {
14
+ ui: inquirer.ui.Prompt<any>;
15
+ };
16
+ export declare const promptAuth: () => Promise<any> & {
17
+ ui: inquirer.ui.Prompt<any>;
18
+ };
19
+ export declare const promptPasswordAuth: () => Promise<any> & {
20
+ ui: inquirer.ui.Prompt<any>;
21
+ };
22
+ export declare const promptTokenAuth: () => Promise<any> & {
23
+ ui: inquirer.ui.Prompt<any>;
24
+ };
25
+ export declare const promptWatAuth: () => Promise<any> & {
26
+ ui: inquirer.ui.Prompt<any>;
27
+ };
28
+ export declare const promptDataModel: () => Promise<any> & {
29
+ ui: inquirer.ui.Prompt<any>;
30
+ };
@@ -0,0 +1,101 @@
1
+ import inquirer from 'inquirer';
2
+ import { validateNotEmpty } from './interactive.js';
3
+ export const promptPasswordInteractive = (username) => inquirer.prompt([
4
+ {
5
+ type: 'password',
6
+ name: 'maskedPassword',
7
+ mask: '*',
8
+ message: `Enter password for username '${username}':`,
9
+ validate: (answer) => {
10
+ if (!answer || answer === '') {
11
+ return 'Password cannot be blank';
12
+ }
13
+ return true;
14
+ },
15
+ },
16
+ ]);
17
+ export const promptCommand = () => inquirer.prompt([
18
+ {
19
+ type: 'rawlist',
20
+ name: 'command',
21
+ message: 'Select command to run:',
22
+ choices: ['get-data-model'],
23
+ },
24
+ ]);
25
+ export const promptUrl = () => inquirer.prompt([
26
+ {
27
+ type: 'input',
28
+ name: 'hostname',
29
+ message: 'Specify the Sisense server IP address or hostname (example: 10.50.1.5):',
30
+ validate: validateNotEmpty,
31
+ },
32
+ {
33
+ type: 'number',
34
+ name: 'port',
35
+ message: 'Specify the Sisense server port or leave blank for default port:',
36
+ default: 30845,
37
+ },
38
+ {
39
+ type: 'list',
40
+ name: 'protocol',
41
+ message: 'Select http/https:',
42
+ choices: ['http', 'https'],
43
+ default: 'http',
44
+ },
45
+ ]);
46
+ export const promptAuth = () => inquirer.prompt([
47
+ {
48
+ type: 'list',
49
+ name: 'auth',
50
+ message: 'Select authentication method:',
51
+ choices: ['password', 'token', 'web access token'],
52
+ default: 'password',
53
+ },
54
+ ]);
55
+ export const promptPasswordAuth = () => inquirer.prompt([
56
+ {
57
+ type: 'input',
58
+ name: 'username',
59
+ message: 'Specify the username for username/password authentication:',
60
+ },
61
+ {
62
+ type: 'password',
63
+ name: 'password',
64
+ mask: '*',
65
+ message: 'Specify the password for username/password authentication:',
66
+ validate: (input, answers) => {
67
+ if (answers.username && answers.username !== '' && !input) {
68
+ return 'if username is provided password cannot be blank';
69
+ }
70
+ return true;
71
+ },
72
+ },
73
+ ]);
74
+ export const promptTokenAuth = () => inquirer.prompt([
75
+ {
76
+ type: 'input',
77
+ name: 'token',
78
+ message: 'Specify the Bearer token for token-based authentication:',
79
+ },
80
+ ]);
81
+ export const promptWatAuth = () => inquirer.prompt([
82
+ {
83
+ type: 'input',
84
+ name: 'wat',
85
+ message: 'Specify the web access token for token-based authentication:',
86
+ },
87
+ ]);
88
+ export const promptDataModel = () => inquirer.prompt([
89
+ {
90
+ type: 'input',
91
+ name: 'dataSource',
92
+ message: 'Specify the data source name (for example: Sample ECommerce):',
93
+ validate: validateNotEmpty,
94
+ },
95
+ {
96
+ type: 'input',
97
+ name: 'output',
98
+ message: 'Specify the output filename:',
99
+ validate: validateNotEmpty,
100
+ },
101
+ ]);
@@ -0,0 +1,3 @@
1
+ export declare enum TrackingActions {
2
+ Execution = "sdkCliExec"
3
+ }
@@ -0,0 +1,4 @@
1
+ export var TrackingActions;
2
+ (function (TrackingActions) {
3
+ TrackingActions["Execution"] = "sdkCliExec";
4
+ })(TrackingActions = TrackingActions || (TrackingActions = {}));
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @packageDocumentation
4
+ * @beta
5
+ */
6
+ import 'cross-fetch/dist/node-polyfill.js';
7
+ export * from './types.js';
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @packageDocumentation
4
+ * @beta
5
+ */
6
+ // Native fetch() is not available in Node.js until version 18.
7
+ // Polyfill fetch() with cross-fetch for CLI commands if needed.
8
+ // Somehow import 'cross-fetch/polyfill' does not work thus the following workaround
9
+ // eslint-disable-next-line import/extensions
10
+ import 'cross-fetch/dist/node-polyfill.js';
11
+ import { runCli } from './run-cli.js';
12
+ export * from './types.js';
13
+ runCli();
@@ -0,0 +1 @@
1
+ export declare const PKG_VERSION = "0.11.3";
@@ -0,0 +1 @@
1
+ export const PKG_VERSION = "0.11.3";
@@ -0,0 +1 @@
1
+ export declare const runCli: () => void;
@@ -0,0 +1,18 @@
1
+ /* eslint-disable @typescript-eslint/no-floating-promises */
2
+ /* eslint-disable @typescript-eslint/no-unused-expressions */
3
+ import yargs from 'yargs';
4
+ import { hideBin } from 'yargs/helpers';
5
+ import { getDataModelCommand } from './commands/get-data-model.js';
6
+ import { getApiTokenCommand } from './commands/get-api-token.js';
7
+ import { interactiveCommand } from './commands/interactive.js';
8
+ export const runCli = () => {
9
+ yargs(hideBin(process.argv))
10
+ .command(getDataModelCommand)
11
+ .command(interactiveCommand)
12
+ .command(getApiTokenCommand)
13
+ .scriptName('sdk-cli')
14
+ .showHelpOnFail(true)
15
+ .demandCommand(1, 'You need to specify a command to continue')
16
+ .help()
17
+ .strict().argv;
18
+ };
@@ -0,0 +1,2 @@
1
+ import { HttpClient } from '@sisense/sdk-rest-client';
2
+ export declare const trackExecution: <T extends {}>(httpClient: HttpClient, commandName: string, args: T) => void;
@@ -0,0 +1,15 @@
1
+ import { trackProductEvent } from '@sisense/sdk-common';
2
+ import { PKG_VERSION } from './package-version.js';
3
+ import { TrackingActions } from './constants.js';
4
+ export const trackExecution = (httpClient, commandName, args) => {
5
+ const payload = {
6
+ packageVersion: PKG_VERSION,
7
+ commandName,
8
+ argumentsPassed: Object.entries(args)
9
+ .filter(([, v]) => !!v)
10
+ .map(([k]) => k)
11
+ .join(', '),
12
+ };
13
+ const action = TrackingActions.Execution;
14
+ void trackProductEvent(action, payload, httpClient).catch((e) => console.log(`An error occurred when sending the ${action} event`, e));
15
+ };
@@ -0,0 +1,23 @@
1
+ import { DataSource } from '@sisense/sdk-data';
2
+ declare const COMMANDS: readonly ["get-data-model", "interactive", "get-api-token"];
3
+ /**
4
+ * The commands supported by the CLI tool.
5
+ *
6
+ * @expandType
7
+ */
8
+ export declare type Command = (typeof COMMANDS)[number];
9
+ export declare type GetDataModelOptions = {
10
+ url: string;
11
+ dataSource: DataSource;
12
+ username: string | undefined;
13
+ password: string | undefined;
14
+ token: string | undefined;
15
+ wat: string | undefined;
16
+ output: string | undefined;
17
+ };
18
+ export declare type GetApiTokenOptions = {
19
+ url: string;
20
+ username: string;
21
+ password: string | undefined;
22
+ };
23
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ const COMMANDS = ['get-data-model', 'interactive', 'get-api-token'];
2
+ export {};
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@sisense/sdk-cli",
3
+ "description": "CLI for generating programmatic interface from Sisense data model",
4
+ "version": "0.11.3",
5
+ "type": "module",
6
+ "exports": "./dist/index.js",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "author": "Sisense",
10
+ "license": "SEE LICENSE IN LICENSE.md",
11
+ "bin": "./dist/index.js",
12
+ "dependencies": {
13
+ "@sisense/sdk-common": "^0.11.3",
14
+ "@sisense/sdk-data": "^0.11.3",
15
+ "@sisense/sdk-modeling": "^0.11.3",
16
+ "@sisense/sdk-query-client": "^0.11.3",
17
+ "@sisense/sdk-rest-client": "^0.11.3",
18
+ "cross-fetch": "^4.0.0",
19
+ "inquirer": "^8.1.2",
20
+ "yargs": "17.7.1"
21
+ },
22
+ "scripts": {
23
+ "cli": "node ./dist/index.js",
24
+ "prebuild": "node -p \"'export const PKG_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/package-version.ts",
25
+ "type-check": "run prebuild && tsc --noEmit",
26
+ "build": "run prebuild && tsc --build tsconfig.build.json",
27
+ "build:prod": "run prebuild && tsc --project tsconfig.prod.json",
28
+ "clean": "rm -rf dist coverage tsconfig.build.tsbuildinfo tsconfig.prod.tsbuildinfo",
29
+ "lint": "eslint . --fix",
30
+ "format": "prettier --write .",
31
+ "format:check": "prettier --check .",
32
+ "vitest": "run -T vitest",
33
+ "test": "run vitest run",
34
+ "test:watch": "run vitest watch",
35
+ "test:coverage": "run vitest run --coverage"
36
+ },
37
+ "files": [
38
+ "src-js/",
39
+ "dist/",
40
+ "./"
41
+ ],
42
+ "devDependencies": {
43
+ "@babel/preset-env": "^7.20.2",
44
+ "@types/inquirer": "8.2.6",
45
+ "@types/yargs": "^17.0.22",
46
+ "eslint": "^8.40.0",
47
+ "prettier": "2.8.4",
48
+ "typescript": "4.8.4",
49
+ "vitest-fetch-mock": "^0.2.2"
50
+ },
51
+ "volta": {
52
+ "extends": "../../package.json"
53
+ }
54
+ }