zendesk / zcli

A command-line tool for Zendesk
https://developer.zendesk.com
Apache License 2.0
56 stars 18 forks source link

Unable to run themes:preview without specifying profile #208

Open equalsgibson opened 8 months ago

equalsgibson commented 8 months ago

Expectations

When setting environment variables to be used with ZCLI, I expect to be able to run commands and be authenticated.

Reality

After setting the following environment variables:

ubuntu@dev-cgibson:~/git/zendesk-theme/dist$ zcli themes:preview
Uploading theme... Ok
/usr/lib/node_modules/@zendesk/zcli/node_modules/@zendesk/zcli-themes/dist/commands/themes/preview.js:60
            const { subdomain, domain } = await new zcli_core_1.Auth().getLoggedInProfile();
                    ^

TypeError: Cannot destructure property 'subdomain' of '(intermediate value)' as it is undefined.
    at Server.<anonymous> (/usr/lib/node_modules/@zendesk/zcli/node_modules/@zendesk/zcli-themes/dist/commands/themes/preview.js:60:21)

Node.js v18.17.0

This appears to be an issue with the following code, where an assumption is made that the subdomain will always be coming from the logged in profile:

/usr/lib/node_modules/@zendesk/zcli/node_modules/@zendesk/zcli-themes/dist/commands/themes/preview.js

        server.listen(port, host, async () => {
            // preview requires authentication so we're sure
            // to have a logged in profile at this point
            const { subdomain, domain } = await new zcli_core_1.Auth().getLoggedInProfile();
            const baseUrl = (0, zcli_core_1.getBaseUrl)(subdomain, domain);
            this.log(chalk.bold.green('Ready', chalk.blueBright(`${baseUrl}/hc/admin/local_preview/start`, '🚀')));
            this.log(`You can exit preview mode in the UI or by visiting ${baseUrl}/hc/admin/local_preview/stop`);
            tailLogs && this.log(chalk.bold('Tailing logs'));
        });

TEMPORARY FIX For my use case, I was able to resolve this by editing the above file and changing:

const { subdomain, domain } = await new zcli_core_1.Auth().getLoggedInProfile();
const baseUrl = (0, zcli_core_1.getBaseUrl)(subdomain, domain);

to:

// const { subdomain, domain } = await new zcli_core_1.Auth().getLoggedInProfile();
// const baseUrl = (0, zcli_core_1.getBaseUrl)(subdomain, domain);
const baseUrl = (0, zcli_core_1.getBaseUrl)("mysubdomain", "zendesk.com");

Steps to Reproduce

  1. Uninstall & reinstall the latest version of zcli globally: sudo npm uninstall -g @zendesk/zcli; sudo npm install @zendesk/zcli -g
  2. Set your environment variables and resource your shell
  3. Check your environment variables are set
  4. Run zcli themes:preview

Issue details