()
| 83 | // clientIdProvider. If both are specified, environment wins. If only one is specified, calculate |
| 84 | // the other based on it. If neither is specified, use the globalClientIdProvider. |
| 85 | const calculateEnvironment = (): [string, SmartThingsURLProvider] => { |
| 86 | const environment = (flags.environment ?? stCommand.cliConfig.stringConfigValue('environment')) || undefined |
| 87 | // first look for environment; then fall back to the old config style |
| 88 | if (environment) { |
| 89 | if (environment in urlProvidersByEnvironment) { |
| 90 | return [environment, urlProvidersByEnvironment[environment]] |
| 91 | } |
| 92 | return fatalError(`unknown environment: ${environment}`) |
| 93 | } |
| 94 | |
| 95 | const configClientIdProvider = stCommand.profile.clientIdProvider |
| 96 | if (configClientIdProvider) { |
| 97 | if (typeof configClientIdProvider !== 'object') { |
| 98 | stCommand.logger.error('ignoring invalid configClientIdProvider') |
| 99 | } else { |
| 100 | const clientIdProvider = configClientIdProvider as ClientIdProvider |
| 101 | // Look up the environment based on the clientIdProvider.baseURL. |
| 102 | const environment = Object.entries(urlProvidersByEnvironment) |
| 103 | .find(([, provider]) => provider.baseURL === clientIdProvider.baseURL)?.[0] |
| 104 | ?? 'unknown' |
| 105 | return [environment, clientIdProvider] |
| 106 | } |
| 107 | } |
| 108 | return ['global', globalClientIdProvider] |
| 109 | } |
| 110 | |
| 111 | const [environment, urlProvider] = calculateEnvironment() |
| 112 | const logger = coreSDKLoggerFromLog4JSLogger(log4js.getLogger('rest-client')) |
no test coverage detected