@sap/datasphere-cli 2023.14.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project SAP Datasphere Command-Line Interface (DS CLI) will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## 2023.10.0
9
+
10
+ Package `@sap/datasphere-cli` was released.
package/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ SAP FREEWARE LICENSE AGREEMENT
2
+
3
+ Please scroll down and read the following SAP Freeware License Agreement carefully ("Agreement"). By downloading, installing, or otherwise using the SAP Freeware or any materials that accompany the Freeware documentation (collectively, the "Freeware"), You agree that this Agreement forms a legally binding agreement between You ("You" or "Your") and SAP SE, for and on behalf of itself and its subsidiaries and affiliates (as defined in Section 15 of the German Stock Corporation Act), and You agree to be bound by all of the terms and conditions stated in this Agreement. If You are trying to access or download the Freeware on behalf of Your employer or as a consultant or agent of a third party (either "Your Company"), You represent and warrant that You have the authority to act on behalf of and bind Your Company to the terms of this Agreement and everywhere in this Agreement that refers to 'You' or 'Your' shall also include Your Company. If You do not agree to these terms, do not attempt to access or use the Freeware.
4
+
5
+ 1. LICENSE: Subject to the terms of this Agreement, SAP grants You a non- exclusive, non-transferable, non-sublicensable, revocable, royalty-free, limited license to use and copy the Freeware solely for Your internal business purposes.
6
+
7
+ 2. RESTRICTIONS: You must not use the Freeware to: (a) impair, degrade or reduce the performance or security of any SAP products, services or related technology (collectively, "SAP Products"); (b) enable the bypassing or circumventing of SAP's license restrictions and/or provide users with access to the SAP Products to which such users are not licensed; or (c) permit mass data extraction from an SAP Product to a non-SAP Product, including use, modification, saving or other processing of such data in the non-SAP Product. Further, You must not: (i) provide or make the Freeware available to any third party other than your authorized employees, contractors and agents (collectively, "Representatives") and solely to be used by Your Representatives for Your own internal business purposes; ii) remove or modify any marks or proprietary notices from the Freeware; iii) assign this Agreement, or any interest therein, to any third party; (iv) use any SAP name, trademark or logo without the prior written authorization of SAP; or (v) use the Freeware to modify an SAP Product or decompile, disassemble or reverse engineer an SAP Product (except to the extent permitted by applicable law). You are responsible for any breach of the terms of this Agreement by You or Your Representatives.
8
+
9
+ 3. INTELLECTUAL PROPERTY: SAP or its licensors retain all ownership and intellectual property rights in and to the Freeware and SAP Products. In exchange for the right to use and copy the Freeware provided under this Agreement, You covenant not to assert any intellectual property rights in or to any of Your products, services, or related technology that are based on or incorporate the Freeware against any individual or entity in respect of any current or future SAP Products.
10
+
11
+ 4. SAP AND THIRD PARTY APIS: The Freeware may include API (application programming interface) calls to SAP and third-party products or services. The access or use of the third-party products and services to which the API calls are directed may be subject to additional terms and conditions between you and SAP or such third parties. You (and not SAP) are solely responsible for understanding and complying with any additional terms and conditions that apply to the access or use of those APIs and/or third-party products and
12
+ services. SAP does not grant You any rights in or to these APIs, products or services under this Agreement.
13
+
14
+ 5. FREE AND OPEN SOURCE COMPONENTS: The Freeware may include third party free or open source components ("FOSS Components"). You may have additional rights in such FOSS Components that are provided by the third party licensors of those components.
15
+
16
+ 6. THIRD PARTY DEPENDENCIES: The Freeware may require third party software dependencies ("Dependencies") for the use or operation of the Freeware. These Dependencies may be identified by SAP in Maven POM files, documentation or by other means. SAP does not grant You any rights in or to such Dependencies under this Agreement. You are solely responsible for the acquisition, installation and use of such Dependencies.
17
+
18
+ 7. WARRANTY:
19
+ a) If You are located outside the US or Canada: AS THE FREEWARE IS PROVIDED TO YOU FREE OF CHARGE, SAP DOES NOT GUARANTEE OR WARRANT ANY FEATURES OR QUALITIES OF THE FREEWARE OR GIVE ANY UNDERTAKING WITH REGARD TO ANY OTHER QUALITY. NO SUCH WARRANTY OR UNDERTAKING SHALL BE IMPLIED BY YOU FROM ANY DESCRIPTION IN THE FREEWARE OR ANY OTHER MATERIALS, COMMUNICATION OR ADVERTISEMENT. IN PARTICULAR, SAP DOES NOT WARRANT THAT THE FREEWARE WILL BE AVAILABLE UNINTERRUPTED, ERROR FREE, OR PERMANENTLY AVAILABLE. ALL WARRANTY CLAIMS RESPECTING THE FREEWARE ARE SUBJECT TO THE LIMITATION OF LIABILITY STIPULATED IN SECTION 8 BELOW.
20
+ b) If You are located in the US or Canada: THE FREEWARE IS LICENSED TO YOU "AS IS", WITHOUT ANY WARRANTY, ESCROW, TRAINING, MAINTENANCE, OR SERVICE OBLIGATIONS WHATSOEVER ON THE PART OF SAP. SAP MAKES NO EXPRESS OR IMPLIED WARRANTIES OR CONDITIONS OF SALE OF ANY TYPE WHATSOEVER, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND OF FITNESS FOR A PARTICULAR PURPOSE. IN PARTICULAR, SAP DOES NOT WARRANT THAT THE FREEWARE WILL BE AVAILABLE UNINTERRUPTED, ERROR FREE, OR PERMANENTLY AVAILABLE. YOU ASSUME ALL RISKS ASSOCIATED WITH THE USE OF THE FREEWARE, INCLUDING WITHOUT LIMITATION RISKS RELATING TO QUALITY, AVAILABILITY, PERFORMANCE, DATA LOSS, AND UTILITY IN A PRODUCTION ENVIRONMENT.
21
+ c) For all locations: SAP DOES NOT MAKE ANY REPRESENTATIONS OR WARRANTIES IN RESPECT OF THIRD PARTY DEPENDENCIES, APIS, PRODUCTS AND SERVICES, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND OF FITNESS FOR A PARTICULAR PURPOSE. IN PARTICULAR, SAP DOES NOT WARRANT THAT THIRD- PARTY DEPENDENCIES, APIS, PRODUCTS AND SERVICES WILL BE AVAILABLE, ERROR FREE, INTEROPERABLE WITH THE FREEWARE, SUITABLE FOR ANY PARTICULAR PURPOSE OR NON- INFRINGING. YOU ASSUME ALL RISKS ASSOCIATED WITH THE USE OF THIRD PARTY DEPENDENCIES, APIS, PRODUCTS AND SERVICES, INCLUDING WITHOUT LIMITATION RISKS RELATING TO QUALITY, AVAILABILITY, PERFORMANCE, DATA LOSS, UTILITY IN A PRODUCTION ENVIRONMENT, AND NON-INFRINGEMENT. IN NO EVENT WILL SAP BE LIABLE DIRECTLY OR INDIRECTLY IN RESPECT OF ANY USE OF THIRD PARTY DEPENDENCIES, APIS, PRODUCTS AND SERVICES BY YOU.
22
+
23
+ 8. LIMITATION OF LIABILITY:
24
+ a) If You are located outside the US or Canada: IRRESPECTIVE OF THE LEGAL REASONS, SAP SHALL ONLY BE LIABLE FOR DAMAGES UNDER THIS AGREEMENT IF SUCH DAMAGE (I) CAN BE CLAIMED UNDER THE GERMAN PRODUCT LIABILITY ACT OR (II) IS CAUSED BY INTENTIONAL MISCONDUCT OF SAP OR (III) CONSISTS OF PERSONAL INJURY. IN ALL OTHER CASES, NEITHER SAP NOR ITS EMPLOYEES, AGENTS AND SUBCONTRACTORS SHALL BE LIABLE FOR ANY KIND OF DAMAGE OR CLAIMS HEREUNDER.
25
+ b) If You are located in the US or Canada: IN NO EVENT SHALL SAP BE LIABLE TO
26
+ YOU, YOUR COMPANY OR TO ANY THIRD PARTY FOR ANY DAMAGES IN AN AMOUNT IN EXCESS OF $100 ARISING IN CONNECTION WITH YOUR USE OF OR INABILITY TO USE THE FREEWARE OR IN CONNECTION WITH SAP'S PROVISION OF OR FAILURE TO PROVIDE SERVICES
27
+ PERTAINING TO THE FREEWARE, OR AS A RESULT OF ANY DEFECT IN THE FREEWARE. THIS DISCLAIMER OF LIABILITY SHALL APPLY REGARDLESS OF THE FORM OF ACTION THAT MAY BE BROUGHT AGAINST SAP, WHETHER IN CONTRACT OR TORT, INCLUDING WITHOUT LIMITATION ANY ACTION FOR NEGLIGENCE. YOUR SOLE REMEDY IN THE EVENT OF BREACH OF THIS AGREEMENT BY SAP OR FOR ANY OTHER CLAIM RELATED TO THE FREEWARE SHALL BE TERMINATION OF THIS AGREEMENT. NOTWITHSTANDING ANYTHING TO THE CONTRARY HEREIN, UNDER NO CIRCUMSTANCES SHALL SAP OR ITS LICENSORS BE LIABLE TO YOU OR ANY OTHER PERSON OR ENTITY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR INDIRECT DAMAGES, LOSS OF GOOD WILL OR BUSINESS PROFITS, WORK STOPPAGE, DATA LOSS, COMPUTER FAILURE OR MALFUNCTION, ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSS, OR EXEMPLARY OR PUNITIVE DAMAGES.
28
+
29
+ 9. INDEMNITY: You will fully indemnify, hold harmless and defend SAP against law suits based on any claim: (a) that any of Your products, services or related technology that are based on or incorporate the Freeware infringes or misappropriates any patent, copyright, trademark, trade secrets, or other proprietary rights of a third party, or (b) related to Your alleged violation of the terms of this Agreement.
30
+
31
+ 10. EXPORT: The Freeware is subject to German, EU and US export control regulations. You confirm that: a) You will not use the Freeware for, and will not allow the Freeware to be used for, any purposes prohibited by German, EU and US law, including, without limitation, for the development, design, manufacture or production of nuclear, chemical or biological weapons of mass destruction; b) You are not located in Cuba, Iran, Sudan, Iraq, North Korea, Syria, nor any other country to which the United States has prohibited export or that has been designated by the U.S. Government as a "terrorist supporting" country (any, an "US Embargoed Country"); c) You are not a citizen, national or resident of, and are not under the control of, a US Embargoed Country; d) You will not download or otherwise export or re-export the Freeware, directly or indirectly, to a US Embargoed Country nor to citizens, nationals or residents of a US Embargoed Country; e) You are not listed on the United States Department of Treasury lists of Specially Designated Nationals, Specially Designated Terrorists, and Specially Designated Narcotic Traffickers, nor listed on the United States Department of Commerce Table of Denial Orders or any other U.S. government list of prohibited or restricted parties and f) You will not download or otherwise export or re-export the Freeware, directly or indirectly, to persons on the above-mentioned lists.
32
+
33
+ 11. SUPPORT: SAP does not offer support for the Freeware.
34
+
35
+ 12. TERM AND TERMINATION: You may terminate this Agreement by destroying all copies of the Freeware in Your possession or control. SAP may terminate Your license to use the Freeware immediately if You fail to comply with any of the terms of this Agreement, or, for SAP's convenience by providing you with ten (10) days written notice of termination. In case of termination or expiration of this Agreement, You must immediately destroy all copies of the Freeware in your possession or control. In the event Your Company is acquired (by merger, purchase of stock, assets or intellectual property or exclusive license), or You become employed, by a direct competitor of SAP, then this Agreement and
36
+ all licenses granted to You in this Agreement shall immediately terminate upon the date of such acquisition or change of employment.
37
+
38
+ 13. LAW/VENUE:
39
+ a) If You are located outside the US or Canada: This Agreement is governed by and construed in accordance with the laws of Germany without reference to its conflicts of law principles. You and SAP agree to submit to the exclusive
40
+ jurisdiction of, and venue in, the courts located in Karlsruhe, Germany in any dispute arising out of or relating to this Agreement or the Freeware. The United Nations Convention on Contracts for the International Sale of Goods shall not apply to this Agreement.
41
+ b) If You are located in the US or Canada: This Agreement shall be governed by and construed in accordance with the laws of the State of New York, USA without reference to its conflicts of law principles. You and SAP agree to submit to the exclusive jurisdiction of, and venue in, the courts located in New York, New York, USA in any dispute arising out of or relating to this Agreement or the Freeware. The United Nations Convention on Contracts for the International Sale of Goods shall not apply to this Agreement.
42
+
43
+ 14. MISCELLANEOUS: This Agreement is the complete agreement between the parties respecting the Freeware. This Agreement supersedes all prior or contemporaneous agreements or representations with regards to the Freeware. If any term of this Agreement is found to be invalid or unenforceable, the surviving provisions shall remain effective. SAP's failure to enforce any right or provisions stipulated in this Agreement will not constitute a waiver of such provision, or any other provision of this Agreement.
44
+
package/README.md ADDED
@@ -0,0 +1,471 @@
1
+ # @sap/datasphere-cli
2
+
3
+ Command-Line Interface (CLI) for SAP Datasphere.
4
+
5
+ [![Node Version](https://img.shields.io/badge/node-16.xx.x-brightgreen)](https://nodejs.org/dist/latest-v16.x/docs/api/#) [![npm version](https://badge.fury.io/js/@sap%2Fdatasphere-cli.svg)](https://badge.fury.io/js/@sap%2Fdatasphere-cli) [![Documentation](https://img.shields.io/badge/docs-online-ff69b4.svg)](https://help.sap.com/docs/SAP_DATASPHERE/d0ecd6f297ac40249072a44df0549c1a/3f9a42ccde6b4b6aba121e2aab79c36d.html) [![Command help pages](https://img.shields.io/badge/command-help-lightgrey.svg)](#usage) ![NPM](https://img.shields.io/npm/l/@sap/datasphere-cli?color=%23FFFF00)
6
+
7
+ ## Content
8
+
9
+ 1. [Installation](#installation)
10
+ 1. [Update the CLI](#update-the-cli)
11
+ 1. [Versioning](#versioning)
12
+ 1. [Authentication](#authentication)
13
+ 1. [OAuth Interactive Usage](#oauth-interactive-usage)
14
+ 1. [Passcodes](#passcodes)
15
+ 1. [Usage](#usage)
16
+ 1. [From the command line](#from-the-command-line)
17
+ 1. [As a Node.js module dependency](#as-a-nodejs-module-dependency)
18
+ 1. [Options Handling](#options-handling)
19
+ 1. [Environment Variables](#environment-variables)
20
+ 1. [Help & Documentation](#help-documentation)
21
+ 1. [Community & Feedback](#community--feedback)
22
+ 1. [License](#license)
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ $ npm install -g @sap/datasphere-cli
28
+ ```
29
+
30
+ or
31
+
32
+ ```bash
33
+ $ yarn global add @sap/datasphere-cli
34
+ ```
35
+
36
+ ## Update the CLI
37
+
38
+ See [Installation](#installation).
39
+
40
+ In case of structural changes applied to the service document (see [Initialize the CLI](#initialize-the-cli)) with a new version of SAP Datasphere you need to update the CLI. In this case, after you executed a command, the CLI issues a warning:
41
+
42
+ ```bash
43
+ $ datasphere <command>
44
+ Your local CLI installation is outdated. Run 'npm install @sap/datasphere-cli [-g]' to update
45
+ ```
46
+
47
+ ## Versioning
48
+
49
+ The semantic versioning of the CLI is handled according to SAP Datasphere versions and follows the same structure for major and minor versions.
50
+
51
+ ```bash
52
+ $ datasphere -v
53
+ 2021.21.0
54
+ ```
55
+
56
+ For an in-depth explanation see the blog post on [blogs.sap.com](https://blogs.sap.com/2021/09/21/new-command-line-for-sap-data-warehouse-cloud-code-way-to-the-cloud/).
57
+
58
+ ## Authentication
59
+
60
+ ### OAuth Interactive Usage
61
+
62
+ You can create an [OAuth Client for Interactive Usage](https://help.sap.com/docs/SAP_DATASPHERE/c8a54ee704e94e15926551293243fd1d/3f92b46fe0314e8ba60720e409c219fc.html) and authenticate using the provided _Client ID_ and _Client Secret_. After you created an OAuth Client for Interactive Usage, you can log in once and run multiple commands without the need to authenticate again for the next 720 hours.
63
+
64
+ To log in, run the `login` command and provide the _Client ID_, _Client Secret_, _Authentication URL_, and _Token URL_, available from your SAP Datasphere tenant ([SAP Help](https://help.sap.com/docs/SAP_DATASPHERE/c8a54ee704e94e15926551293243fd1d/3f92b46fe0314e8ba60720e409c219fc.html)).
65
+
66
+ ```bash
67
+ $ datasphere login
68
+ ✔ Please enter your client ID: … <Client ID>
69
+ ✔ Please enter your client secret: … ****
70
+ ✔ Please enter your authorization URL: … <Authorization URL>
71
+ ✔ Please enter your token URL: … <Token URL>
72
+ ```
73
+
74
+ To remove any data stored by running the `login` command, log out again:
75
+
76
+ ```bash
77
+ $ datasphere logout
78
+ ```
79
+
80
+ To display the locally stored secrets, run the `secrets show` command:
81
+
82
+ ```bash
83
+ $ datasphere secrets show
84
+ {
85
+ "client_id": "...",
86
+ "client_secret": "...",
87
+ "authorization_url": "...",
88
+ "token_url": "...",
89
+ "access_token": "...",
90
+ "token_type": "...",
91
+ "id_token": "...",
92
+ "refresh_token": "...",
93
+ "expires_in": ...,
94
+ "scope": "...",
95
+ "jti": "...",
96
+ "expires_after": ...
97
+ }
98
+ ```
99
+
100
+ If you do not want to log in and have the CLI store the secrets in the CLI cache locally, you can also provide the _access_token_ directly on the command line:
101
+
102
+ ```bash
103
+ $ datasphere cache init --host <my host> --access-token <access token>
104
+ ```
105
+
106
+ Alternatively, you can provide the _access_token_ through a `secrets.json` file:
107
+
108
+ ```bash
109
+ $ datasphere cache init --host <my host> -secrets-file /path/to/secrets.json
110
+ ```
111
+
112
+ The `secrets.json` file must at least contain a property called `access_token`:
113
+
114
+ ```json
115
+ // secrets.json
116
+
117
+ {
118
+ "access_token": "<access token>"
119
+ }
120
+ ```
121
+
122
+ ### Passcodes
123
+
124
+ Passcodes are used for authenticating commands sent from the CLI to your SAP Datasphere tenant. Passcodes can be provided explicitly using the `-p, --passcode` option in case the URL to retrieve a passcode is known, or implictly using an interactive session by omitting the `-p, --passcode` option.
125
+
126
+ When omitting the `-p, --passcode` option the CLI prompts you to provide a passcode by navigating to the passcode authentication URL for your tenant. The URL is calculated based on the provided `-H, --host` value.
127
+
128
+ ```bash
129
+ $ datasphere cache init -H https://mytenant.eu10.hcs.cloud.sap/
130
+ ✔ Do you want to retrieve a passcode from https://mytenant.authentication.eu10.hana.ondemand.com/passcode? … yes
131
+ ✔ Enter your temporary authentication code: … **********
132
+ ...
133
+ ```
134
+
135
+ The displayed URL can be used for retrieving more passcodes by refreshing the page when sending multiple commands which can then be fed to the `-p, --passcode` option.
136
+
137
+ You can retrieve the URL directly by running the `passcode-url` command:
138
+
139
+ ```bash
140
+ $ datasphere passcode-url -H https://mytenant.eu10.hcs.cloud.sap/
141
+ https://mytenant.authentication.eu10.hana.ondemand.com/passcode
142
+ ```
143
+
144
+ ## Usage
145
+
146
+ You can either use the CLI from the terminal or command line, or use the module as a regular dependency in your code of your Node.js project.
147
+
148
+ ### From the command line
149
+
150
+ #### Initialize the CLI
151
+
152
+ Before you can list and run commands against your SAP Datasphere tenant you need to initialize the CLI first. When initializing the CLI a service document is downloaded from your SAP Datasphere tenant which describes the commands your tenant is able to understand. To initialize the CLI run
153
+
154
+ ```bash
155
+ $ datasphere cache init -H https://mytenant.eu10.hcs.cloud.sap/ -p somepasscode
156
+ ```
157
+
158
+ You can refresh the local copy of the service document by running the `cache init` command again.
159
+
160
+ After you executed a command the CLI issues a warning in case the local version of the service document is outdated. In that case, run the `cache init` command again.
161
+
162
+ ```bash
163
+ $ datasphere <command>
164
+ Your local CLI cache is outdated. Run 'datasphere cache init' to update
165
+ ```
166
+
167
+ #### List available commands
168
+
169
+ To list available commands and required or optional options attach the `-h, --help` to the top-level `datasphere` command or any subcommand of `datasphere`:
170
+
171
+ ```bash
172
+ $ datasphere -h
173
+ Usage: datasphere [options] [command]
174
+
175
+ Command-Line Interface for SAP Datasphere.
176
+
177
+ Options:
178
+ -v, --version output the current version
179
+ -H, --host <host> specifies the urlspecifies the url host where the tenant is hosted where the tenant is hosted
180
+ -h, --help display help for command
181
+
182
+ Commands:
183
+ cache clean clean the local CLI cache
184
+ cache init [options] initialize the local CLI cache
185
+ passcode-url [options] print the passcode url
186
+ help [command] display help for command
187
+ ```
188
+
189
+ To list commands for a tenant for which the CLI was initialized, add the `-H, --host` option (notice the additional command `spaces`):
190
+
191
+ ```bash
192
+ $ datasphere -H https://mytenant.eu10.hcs.cloud.sap/ -h
193
+ Usage: datasphere [options] [command]
194
+
195
+ Command-Line Interface for SAP Datasphere.
196
+
197
+ Options:
198
+ -v, --version output the current version
199
+ -H, --host <host> specifies the url where the tenant is hosted
200
+ -h, --help display help for command
201
+
202
+ Commands:
203
+ cache clean clean the local CLI cache
204
+ cache init [options] initialize the local CLI cache
205
+ spaces manage and orchestrate spaces
206
+ passcode-url [options] print the passcode url
207
+ help [command] display help for command
208
+ ```
209
+
210
+ To show available subcommands for a top-level command, run eg:
211
+
212
+ ```bash
213
+ $ datasphere spaces -H https://mytenant.eu10.hcs.cloud.sap/ -h
214
+ Usage: datasphere spaces [options] [command]
215
+
216
+ manage and orchestrate spaces
217
+
218
+ Options:
219
+ -H, --host <host> specifies the url where the tenant is hosted
220
+ -h, --help display help for command
221
+
222
+ Commands:
223
+ create [options] creates or updates space details based on an import file
224
+ read [options] fetches space details for a specified space
225
+ delete [options] delete an existing space
226
+ help [command] display help for command
227
+ ```
228
+
229
+ ```bash
230
+ $ datasphere spaces create -H https://mytenant.eu10.hcs.cloud.sap/ -h
231
+ Usage: datasphere spaces create [options]
232
+
233
+ creates or updates space details based on an import file
234
+
235
+ Options:
236
+ -f, --filePath <filePath> specifies the file to use as input for the command
237
+ -V, --verbose print detailed log information to console (optional)
238
+ -H, --host <host> specifies the url where the tenant is hosted
239
+ -p, --passcode <passcode> passcode for interactive session authentication (optional)
240
+ -h, --help display help for command
241
+ ```
242
+
243
+ The list of available commands differs based on the content of the service document you downloaded when running `cache init`.
244
+
245
+ ### As a Node.js module dependency
246
+
247
+ Require the module as usual. You can also use it in your TypeScript project using the `import` syntax.
248
+
249
+ ```javascript
250
+ const datasphere = require("@sap/datasphere-cli");
251
+ ```
252
+
253
+ #### Work with commands
254
+
255
+ The module exports a `getCommands` function which returns a map of available commands. Make sure to always specify the `host` to receive `host`-specific commands. Otherwise, when omitting the `host` information, you will only get the list of general commands like `cache clean`, `cache init`, ...
256
+
257
+ ```javascript
258
+ const MY_HOST = "https://mytenant.eu10.hcs.cloud.sap/";
259
+
260
+ const commands = await datasphere.getCommands(MY_HOST);
261
+
262
+ console.log(commands);
263
+ // {
264
+ // datasphere: [AsyncFunction],
265
+ // 'cache clean': [AsyncFunction],
266
+ // 'cache init': [AsyncFunction],
267
+ // 'passcode-url': [AsyncFunction],
268
+ // 'cache show': [AsyncFunction]
269
+ // 'spaces create': [AsyncFunction]
270
+ // 'spaces read': [AsyncFunction]
271
+ // 'spaces delete': [AsyncFunction]
272
+ // }
273
+ ```
274
+
275
+ You can call any available command and provide required options as follows:
276
+
277
+ ```javascript
278
+ const MY_HOST = "https://mytenant.eu10.hcs.cloud.sap/";
279
+
280
+ const options = {
281
+ "--host": MY_HOST,
282
+ "--passcode": "somepasscode",
283
+ };
284
+
285
+ await commands["cache init"](options);
286
+ ```
287
+
288
+ `options` is a map of available options for the respective command. You have to supply either the short flag or long name of the option, including `-` or `--` for the short flag or long name.
289
+
290
+ #### Handle errors during command execution
291
+
292
+ If the command fails, an error is thrown you can catch and process as usual:
293
+
294
+ ```javascript
295
+ try {
296
+ await commands["cache show"]();
297
+ } catch (err) {
298
+ // ops, the command failed!
299
+ console.log(err);
300
+ }
301
+ ```
302
+
303
+ #### Work with command results
304
+
305
+ The result of executing a command is returned from the function call.
306
+
307
+ ```javascript
308
+ const result = await commands["spaces read"]({
309
+ "--space": "MYSPACE",
310
+ "--host": "https://mytenant.eu10.hcs.cloud.sap/",
311
+ "--passcode": "mypasscode",
312
+ });
313
+
314
+ console.log(result);
315
+ // [
316
+ // [
317
+ // '{\n' +
318
+ // ' "MYSPACE": {\n' +
319
+ // ' "spaceDefinition": {\n' +
320
+ // ' "version": "1.0.4",\n' +
321
+ // ...
322
+ // ' }\n' +
323
+ // ' }\n' +
324
+ // '}'
325
+ // ]
326
+ // ]
327
+ ```
328
+
329
+ #### Provide custom logger function
330
+
331
+ Any output of a command you execute is forwarded to the `logger.output` function. To handle the result yourself, you can provide a custom `logger.output` function implementation:
332
+
333
+ ```javascript
334
+ let result = [];
335
+ const output = (...args) => result.push(args);
336
+ datasphere.configure({ customLogger: { output } });
337
+
338
+ await commands["spaces read"]({
339
+ "--space": "MYSPACE",
340
+ "--host": "https://mytenant.eu10.hcs.cloud.sap/",
341
+ "--passcode": "mypasscode",
342
+ });
343
+
344
+ console.log(result);
345
+ // [
346
+ // [
347
+ // '{\n' +
348
+ // ' "MYSPACE": {\n' +
349
+ // ' "spaceDefinition": {\n' +
350
+ // ' "version": "1.0.4",\n' +
351
+ // ...
352
+ // ' }\n' +
353
+ // ' }\n' +
354
+ // '}'
355
+ // ]
356
+ // ]
357
+ ```
358
+
359
+ #### Provide custom passcode retrieval function
360
+
361
+ You can also provide a custom passcode retrieval function which is called every time before a command is executed. The function is expected to return a promise resolving into a string, the passcode. This way you can, for example, make use of programmatic passcode retrieval as described in [this blog](https://blogs.sap.com/2021/09/27/automatically-add-members-to-spaces-in-sap-data-warehouse-cloud-using-sap-datasphere-cli/) using a headless browser and can omit the `--passcode` option when executing commands. The function needs to be configured only once before executing the first command.
362
+
363
+ ```javascript
364
+ const logger = {
365
+ customLogger: { output: console.log },
366
+ };
367
+
368
+ const passcodeFunction = () => {
369
+ // instantiate headless browser, retrieve passcode, return it
370
+ };
371
+
372
+ datasphere.configure(logger, passcodeFunction);
373
+
374
+ // no --passcode option required
375
+ await commands["spaces read"]({
376
+ "--space": "MYSPACE",
377
+ "--host": "https://mytenant.eu10.hcs.cloud.sap/",
378
+ });
379
+ ```
380
+
381
+ ### Options Handling
382
+
383
+ No matter how you use the CLI ([from the command-line](#from-the-command-line) or [as a Node.js module dependency](#as-a-nodejs-module-dependency)), you can supply values for options in different ways. To get an overview of the existing options per command, run `datasphere <command> --help`:
384
+
385
+ ```bash
386
+ $ datasphere cache init --help
387
+
388
+ Usage: datasphere cache init [options]
389
+
390
+ initialize the local CLI cache
391
+
392
+ Options:
393
+ -V, --verbose print detailed log information to console (optional)
394
+ -O, --options-file <file> path to options file (optional)
395
+ -H, --host <host> specifies the url where the tenant is hosted (optional)
396
+ -p, --passcode <passcode> passcode for interactive session authentication (optional)
397
+ -s, --secrets-file <file> path to secrets file (optional)
398
+ -c, --client-id <id> client id for interactive oauth session authentication (optional)
399
+ -C, --client-secret <secret> client secret for interactive oauth session authentication (optional)
400
+ -a, --authorization-url <url> authorization url for interactive oauth session authentication (optional)
401
+ -t, --token-url <url> token url for interactive oauth session authentication (optional)
402
+ -A, --access-token <token> access token for interactive oauth session authentication (optional)
403
+ -r, --refresh-token <token> refresh token for interactive oauth session authentication (optional)
404
+ -e, --expires-in <expires> expires in information for interactive oauth session authentication (optional)
405
+ -h, --help display help for command
406
+ ```
407
+
408
+ #### On the command-line
409
+
410
+ You can use the short flag or long name to supply an option value on the command-line:
411
+
412
+ ```bash
413
+ $ datasphere cache init --host <host>
414
+ ```
415
+
416
+ #### Using environment variables
417
+
418
+ To provide an option value, the option's long name is translated to CONSTANT_CASE. For example, the option `client-id` can also be provided as follows:
419
+
420
+ ```bash
421
+ $ CLIENT_ID='<my client id>' HOST='my-host' datasphere cache init
422
+ ```
423
+
424
+ #### Provide options file
425
+
426
+ You can provide a JSON file with a map of options, using the option's long names, and point the CLI to it using the [On the command-line](#on-the-command-line) or [Using environment variables](#using-environment-variables) way. Define the file as follows:
427
+
428
+ ```json
429
+ // options-file.json
430
+
431
+ {
432
+ "host": "my-host",
433
+ "client-id": "my client id"
434
+ }
435
+ ```
436
+
437
+ Then, supply it to the CLI:
438
+
439
+ ```bash
440
+ $ datasphere cache init --options-file /path/to/options-file.json
441
+ ```
442
+
443
+ ### Environment Variables
444
+
445
+ The CLI supports the following environment variables. You can set the environment variables when calling the CLI according to the local environment. In addition, the CLI supports the [`dotenv`](https://www.npmjs.com/package/dotenv#usage) module, allowing you to place a `.env` file in the CLI working directory.
446
+
447
+ #### `DWC_CLI_PORT`
448
+
449
+ Defines the port the CLI starts the HTTP server at when logging in when using OAuth clients for authentication.
450
+
451
+ | Type | Required | Default |
452
+ | ------ | -------- | ------- |
453
+ | number | no | 8080 |
454
+
455
+ ## Help Documentation
456
+
457
+ Find the full documentation on [help.sap.com](https://help.sap.com/docs/SAP_DATASPHERE/d0ecd6f297ac40249072a44df0549c1a/3f9a42ccde6b4b6aba121e2aab79c36d.html), check out the blog post on [blogs.sap.com](https://blogs.sap.com/2021/09/21/new-command-line-for-sap-data-warehouse-cloud-code-way-to-the-cloud/) or use option `-h, --help`:
458
+
459
+ ```bash
460
+ $ datasphere <command> -h
461
+ ```
462
+
463
+ ## Community & Feedback
464
+
465
+ SAP Community provides a forum where you can ask and answer questions, and comment and vote on the questions of others and their answers.
466
+
467
+ See [SAP Datasphere community](https://community.sap.com/topics/data-warehouse-cloud) for more details and use the tag _datasphere-cli_ for questions concerning the CLI.
468
+
469
+ ## License
470
+
471
+ This package is provided under the terms of the [SAP Freeware License Agreement](https://tools.hana.ondemand.com/sap-freeware-license.txt).
package/module.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { configure, getCommands } from "@sap/cli-core";
package/module.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCommands = exports.configure = void 0;
4
+ if (process.env.SUPPRESS_NO_CONFIG_WARNING === undefined) {
5
+ process.env.SUPPRESS_NO_CONFIG_WARNING = "true";
6
+ }
7
+ // eslint-disable-next-line import/first
8
+ const utils_1 = require("./utils");
9
+ (0, utils_1.configure)();
10
+ var cli_core_1 = require("@sap/cli-core");
11
+ Object.defineProperty(exports, "configure", { enumerable: true, get: function () { return cli_core_1.configure; } });
12
+ Object.defineProperty(exports, "getCommands", { enumerable: true, get: function () { return cli_core_1.getCommands; } });
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@sap/datasphere-cli",
3
+ "version": "2023.14.0",
4
+ "description": "Command-Line Interface for SAP Datasphere.",
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "author": "SAP SE",
7
+ "homepage": "https://www.sap.com",
8
+ "main": "module.js",
9
+ "bin": {
10
+ "datasphere": "terminal.js"
11
+ },
12
+ "engines": {
13
+ "node": "^16",
14
+ "npm": "^8"
15
+ },
16
+ "keywords": [
17
+ "cli",
18
+ "sap datasphere",
19
+ "datasphere-cli"
20
+ ],
21
+ "dependencies": {
22
+ "@sap/cli-core": "2023.13.0"
23
+ }
24
+ }
package/terminal.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/terminal.js ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /* eslint-disable import/first */
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ if (process.env.SUPPRESS_NO_CONFIG_WARNING === undefined) {
6
+ process.env.SUPPRESS_NO_CONFIG_WARNING = "true";
7
+ }
8
+ const cli_core_1 = require("@sap/cli-core");
9
+ const utils_1 = require("./utils");
10
+ (0, utils_1.configure)();
11
+ void (async () => {
12
+ (0, utils_1.configure)();
13
+ void (0, cli_core_1.run)();
14
+ })();
package/utils.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const configure: () => void;
package/utils.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configure = void 0;
4
+ const cli_core_1 = require("@sap/cli-core");
5
+ const configure = () => {
6
+ (0, cli_core_1.configureCoreModule)({
7
+ name: (0, cli_core_1.getBin)(__dirname),
8
+ packageName: (0, cli_core_1.getPackageName)(__dirname),
9
+ discoveryPath: "/dwaas-core/api/v1/discovery",
10
+ description: (0, cli_core_1.getDescription)(__dirname),
11
+ sapHelpLink: "tinyurl.com/datasphere-cli-help",
12
+ version: (0, cli_core_1.getVersion)(__dirname),
13
+ authenticationMethods: [
14
+ cli_core_1.AuthenticationMethod.oauth,
15
+ cli_core_1.AuthenticationMethod.passcode,
16
+ ],
17
+ });
18
+ };
19
+ exports.configure = configure;