cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to initialize @sap/dwc-cli as Node.js dependency correctly?

7aeser
Product and Topic Expert
Product and Topic Expert
0 Likes
1,190

Hey folks,

I noticed that if I use the @sap/dwc-cli as Node.js dependency within node, that it get not correctly initialized.

So basically i do:

const options = { "--host": myhosturl, "--access-token": "********", "--refresh-token": "**********" }
let client = await dwc.getCommands(tenantURL);
await client["cache init"](options)

But if then want to use other commands like "spaces list", I get a function not work. I also get no error for running cache init so i assume that access token, refresh token and host are correct,
It works if i initialize the cache manually within the terminal.

For solving this i thought of removing the global installation of @sap/dwc-cli, but this does not solve the problem.

Accepted Solutions (0)

Answers (1)

Answers (1)

jascha_meiswinkel
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi lkaeser

is myhosturl and tenantURL the same, does it contain the same value? If the cache init command failed, it would have returned a rejected promise. I assume this didn't happen?

To analyze the situation further, you can provide a custom logger implementation, see https://www.npmjs.com/package/@sap/dwc-cli#provide-custom-logger-function, store all the outputs and errors, and log them to the console.

In addition, you can add the "verbose": true option to the options map to get more insights.

7aeser
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi jascha.kanngiesser ,

i get this logs with verbose option:

[
  [
    '%s %s',
    'GET',
    '<tenant>/dwaas-core/api/v1/discovery'
  ],
  [ '%d %s', 200, 'OK' ],
  [ 'Correlation ID 21f7ae1a-f632-4e89-4562-2428520b2aac' ]
]

So i assume that the request worked. But when i am looking at the commands nothing changed. I do it like

console.log(Object.keys(client))
###
[ 'dwc', 'cache', 'cache init', 'cache clean', 'cache show', 'host', 'host set', 'host show', 'host clean', 'login', 'logout', 'passcode-url', 'secrets', 'secrets show' ]
###
jascha_meiswinkel
Product and Topic Expert
Product and Topic Expert
0 Likes

Have you called client = await dwc.getCommands(tenantURL) again after you had called await client["cache init"](options)?

let client = await dwc.getCommands(tenantURL);
await client["cache init"](options);
client = await dwc.getCommands(tenantURL);