Skip to content

Commit

Permalink
support secret infra
Browse files Browse the repository at this point in the history
  • Loading branch information
RomKadria committed Sep 1, 2024
1 parent 928f7a2 commit fd3d3e0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/api/lib/api-client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { GraphQLClient } from 'graphql-request';
import { ApiVersionType, DEFAULT_VERSION, MONDAY_API_ENDPOINT, QueryVariables } from './constants/index';
import { ApiVersionType, DEFAULT_VERSION, QueryVariables } from './constants/index';
import { Sdk, getSdk } from './generated/sdk';
import pkg from '../package.json';
import { getApiEndpoint } from './shared/get-api-endpoint';

/**
* The `ApiClient` class provides a structured way to interact with the Monday.com API,
Expand All @@ -26,7 +27,7 @@ export class ApiClient {

constructor(token: string, apiVersion: string = DEFAULT_VERSION) {
this.apiVersion = apiVersion;
const endpoint = process.env.MONDAY_API_ENDPOINT || MONDAY_API_ENDPOINT;
const endpoint = getApiEndpoint();
this.client = new GraphQLClient(endpoint, {
headers: {
'Content-Type': 'application/json',
Expand Down
21 changes: 21 additions & 0 deletions packages/api/lib/shared/get-api-endpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { MONDAY_API_ENDPOINT } from '../constants/index';

export const getApiEndpoint = (): string => {
if (process.env.MONDAY_API_ENDPOINT) {
return process.env.MONDAY_API_ENDPOINT;
}

const platformApiSecrets = process.env.PLATFORM_API;
if (platformApiSecrets) {
try {
const platformApiSecretsMap = JSON.parse(platformApiSecrets);
if (platformApiSecretsMap.PLATFORM_API_ENDPOINT) {
return platformApiSecretsMap.PLATFORM_API_ENDPOINT;
}
} catch (error) {
console.error('Failed to parse PLATFORM_API_SECRETS', error);
}
}

return MONDAY_API_ENDPOINT;
};

0 comments on commit fd3d3e0

Please sign in to comment.