diff --git a/src/commands/prepare.test.ts b/src/commands/prepare.test.ts index 71fde855..022eab21 100644 --- a/src/commands/prepare.test.ts +++ b/src/commands/prepare.test.ts @@ -131,12 +131,16 @@ describe('prepare CLI command', () => { jest.mocked(readFile).mockResolvedValueOnce(fileContent); jest.mocked(prepareProviderJson).mockResolvedValueOnce(providerJson); - await expect(instance.execute({ - logger, - userError, - flags: {}, - args: { urlOrPath: 'path/to/FILE.docs.2!87.yaml' }, - })).rejects.toThrow(`Provider name inferred from file name is not valid. Please provide provider name explicitly as second argument.`); + await expect( + instance.execute({ + logger, + userError, + flags: {}, + args: { urlOrPath: 'path/to/FILE.docs.2!87.yaml' }, + }) + ).rejects.toThrow( + `Provider name inferred from file name is not valid. Please provide provider name explicitly as second argument.` + ); }); it('prepares provider json from url', async () => { diff --git a/src/logic/application-code/dotenv/dotenv.test.ts b/src/logic/application-code/dotenv/dotenv.test.ts index 5a7b5b26..627a112b 100644 --- a/src/logic/application-code/dotenv/dotenv.test.ts +++ b/src/logic/application-code/dotenv/dotenv.test.ts @@ -26,6 +26,10 @@ const BEARER_AUTH: SecurityScheme = { const TOKEN = 'sfs_b31314b7fc8...8ec1930e'; const EXISTING_DOTENV = `SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e + +# Set to "on" to enable debug logging +ONESDK_LOG=off + # Deployment zone # for AWS MY_PROVIDER_PARAM_TWO=us-west-1 @@ -45,6 +49,9 @@ describe('createNewDotenv', () => { content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e +# Set to "on" to enable debug logging +ONESDK_LOG=off + # Parameter description MY_PROVIDER_PARAM_ONE= MY_PROVIDER_TOKEN= @@ -60,6 +67,9 @@ MY_PROVIDER_TOKEN= expect(result).toStrictEqual({ content: `# Set your OneSDK token to monitor your usage out-of-the-box. Get yours at https://superface.ai SUPERFACE_ONESDK_TOKEN= + +# Set to "on" to enable debug logging +ONESDK_LOG=off `, newEmptyEnvVariables: ['SUPERFACE_ONESDK_TOKEN'], }); @@ -74,6 +84,9 @@ SUPERFACE_ONESDK_TOKEN= expect(result).toStrictEqual({ content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e + +# Set to "on" to enable debug logging +ONESDK_LOG=off `, newEmptyEnvVariables: [], }); @@ -90,6 +103,9 @@ SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e expect(result).toStrictEqual({ content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e + +# Set to "on" to enable debug logging +ONESDK_LOG=off `, newEmptyEnvVariables: [], }); @@ -106,6 +122,9 @@ SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e +# Set to "on" to enable debug logging +ONESDK_LOG=off + # Parameter description MY_PROVIDER_PARAM_ONE= @@ -129,6 +148,9 @@ MY_PROVIDER_PARAM_TWO=us-west-1 content: `# The token for monitoring your Comlinks at https://superface.ai SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e +# Set to "on" to enable debug logging +ONESDK_LOG=off + # Parameter description MY_PROVIDER_PARAM_ONE= @@ -171,6 +193,10 @@ MY_PROVIDER_TOKEN= expect(result).toStrictEqual({ content: `SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e + +# Set to "on" to enable debug logging +ONESDK_LOG=off + # Deployment zone # for AWS MY_PROVIDER_PARAM_TWO=us-west-1 @@ -193,6 +219,10 @@ MY_PROVIDER_PARAM_ONE= expect(result).toStrictEqual({ content: `SUPERFACE_ONESDK_TOKEN=sfs_b31314b7fc8...8ec1930e + +# Set to "on" to enable debug logging +ONESDK_LOG=off + # Deployment zone # for AWS MY_PROVIDER_PARAM_TWO=us-west-1 diff --git a/src/logic/application-code/dotenv/dotenv.ts b/src/logic/application-code/dotenv/dotenv.ts index a17fc92e..314edb2a 100644 --- a/src/logic/application-code/dotenv/dotenv.ts +++ b/src/logic/application-code/dotenv/dotenv.ts @@ -4,6 +4,7 @@ import { prepareSecurityValues, } from '@superfaceai/ast'; +import { ONESDK_LOG_COMMENT, ONESDK_LOG_ENV } from './onesdk-log'; import { ONESDK_TOKEN_COMMENT, ONESDK_TOKEN_ENV, @@ -27,22 +28,25 @@ export function createNewDotenv({ parameters, security, token, + logEnabled, }: { previousDotenv?: string; providerName: string; parameters?: IntegrationParameter[]; security?: SecurityScheme[]; token?: string | null; + logEnabled?: boolean; }): NewDotenv { const previousContent = previousDotenv ?? ''; const parameterEnvs = getParameterEnvs(providerName, parameters); const securityEnvs = getSecurityEnvs(providerName, security); const tokenEnv = makeTokenEnv(token); + const logEnv = makeLogEnv(logEnabled === true ? 'on' : 'off'); const newEnvsOnly = makeFilterForNewEnvs(previousContent); - const newEnvVariables = [tokenEnv, ...parameterEnvs, ...securityEnvs] + const newEnvVariables = [tokenEnv, logEnv, ...parameterEnvs, ...securityEnvs] .filter(uniqueEnvsOnly) .filter(newEnvsOnly); @@ -54,6 +58,14 @@ export function createNewDotenv({ }; } +function makeLogEnv(logValue = 'off'): EnvVar { + return { + name: ONESDK_LOG_ENV, + value: logValue, + comment: ONESDK_LOG_COMMENT, + }; +} + function makeTokenEnv(token?: string | null): EnvVar { return { name: ONESDK_TOKEN_ENV, diff --git a/src/logic/application-code/dotenv/onesdk-log.ts b/src/logic/application-code/dotenv/onesdk-log.ts new file mode 100644 index 00000000..86755380 --- /dev/null +++ b/src/logic/application-code/dotenv/onesdk-log.ts @@ -0,0 +1,2 @@ +export const ONESDK_LOG_ENV = 'ONESDK_LOG'; +export const ONESDK_LOG_COMMENT = 'Set to "on" to enable debug logging';