Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: read host from ctfl config [PHX-2748] #1231

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,11 @@ export interface ITransformEntriesConfig {
*
* The return value must be an object with the same keys as specified in to. Their values will be written to the respective entry fields for the current locale (i.e. {nameField: 'myNewValue'}). If it returns undefined, this the values for this locale on the entry will be left untouched.
*/
transformEntryForLocale: (fromFields: ContentFields, currentLocale: string, { id }: { id: string }) => any
transformEntryForLocale: (
fromFields: ContentFields,
currentLocale: string,
{ id }: { id: string }
) => any
/** (optional) – If true, the transformed entries will be published. If false, they will remain in draft state. When the value is set to "preserve" items will be published only if the original entry was published as well (default true) */
shouldPublish?: boolean | 'preserve'
}
Expand Down Expand Up @@ -643,6 +647,7 @@ export interface ClientConfig {
requestBatchSize?: number
headers?: Record<string, unknown>
retryLimit?: number
host?: string
}

export type MakeRequest = (requestConfig: axios.AxiosRequestConfig) => axios.AxiosResponse['data']
Expand Down
14 changes: 10 additions & 4 deletions src/bin/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ const configPath = path.resolve(homedir, '.contentfulrc.json')
function getFileConfig(): ClientConfig {
try {
const config = require(configPath)
if (config.cmaToken) {
return { accessToken: config.cmaToken }
let clientConfig: ClientConfig = {}

if (config.host) {
clientConfig.host = config.host
}
if (config.managementToken) {
return { accessToken: config.managementToken }
clientConfig.accessToken = config.managementToken
}
return {}
if (config.cmaToken) {
clientConfig.accessToken = config.cmaToken
}

return clientConfig
} catch (e) {
return {}
}
Expand Down