Skip to content

Commit

Permalink
feat(api): update via SDK Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Jun 6, 2024
1 parent 8470cf4 commit 8768954
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Intercom from 'intercom';

const intercom = new Intercom({
accessToken: process.env['INTERCOM_ACCESS_TOKEN'], // This is the default and can be omitted
environment: 'environment_1', // or 'production' | 'environment_2'; defaults to 'production'
environment: 'eu', // or 'us' | 'au'; defaults to 'us'
});

async function main() {
Expand All @@ -46,7 +46,7 @@ import Intercom from 'intercom';

const intercom = new Intercom({
accessToken: process.env['INTERCOM_ACCESS_TOKEN'], // This is the default and can be omitted
environment: 'environment_1', // or 'production' | 'environment_2'; defaults to 'production'
environment: 'eu', // or 'us' | 'au'; defaults to 'us'
});

async function main() {
Expand Down
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import * as qs from 'qs';
import * as API from './resources/index';

const environments = {
production: 'https://api.intercom.io',
environment_1: 'https://api.eu.intercom.io',
environment_2: 'https://api.au.intercom.io',
us: 'https://api.intercom.io',
eu: 'https://api.eu.intercom.io',
au: 'https://api.au.intercom.io',
};
type Environment = keyof typeof environments;

Expand All @@ -24,9 +24,9 @@ export interface ClientOptions {
* Specifies the environment to use for the API.
*
* Each environment maps to a different base URL:
* - `production` corresponds to `https://api.intercom.io`
* - `environment_1` corresponds to `https://api.eu.intercom.io`
* - `environment_2` corresponds to `https://api.au.intercom.io`
* - `us` corresponds to `https://api.intercom.io`
* - `eu` corresponds to `https://api.eu.intercom.io`
* - `au` corresponds to `https://api.au.intercom.io`
*/
environment?: Environment;

Expand Down Expand Up @@ -97,7 +97,7 @@ export class Intercom extends Core.APIClient {
* API Client for interfacing with the Intercom API.
*
* @param {string | undefined} [opts.accessToken=process.env['INTERCOM_ACCESS_TOKEN'] ?? undefined]
* @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
* @param {Environment} [opts.environment=us] - Specifies the environment URL to use for the API.
* @param {string} [opts.baseURL=process.env['INTERCOM_BASE_URL'] ?? https://api.intercom.io] - Override the default base URL for the API.
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
Expand All @@ -121,7 +121,7 @@ export class Intercom extends Core.APIClient {
accessToken,
...opts,
baseURL,
environment: opts.environment ?? 'production',
environment: opts.environment ?? 'us',
};

if (baseURL && opts.environment) {
Expand All @@ -131,7 +131,7 @@ export class Intercom extends Core.APIClient {
}

super({
baseURL: options.baseURL || environments[options.environment || 'production'],
baseURL: options.baseURL || environments[options.environment || 'us'],
timeout: options.timeout ?? 60000 /* 1 minute */,
httpAgent: options.httpAgent,
maxRetries: options.maxRetries,
Expand Down
8 changes: 2 additions & 6 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,12 @@ describe('instantiate client', () => {
process.env['INTERCOM_BASE_URL'] = 'https://example.com/from_env';

expect(
() => new Intercom({ accessToken: 'My Access Token', environment: 'production' }),
() => new Intercom({ accessToken: 'My Access Token', environment: 'us' }),
).toThrowErrorMatchingInlineSnapshot(
`"Ambiguous URL; The \`baseURL\` option (or INTERCOM_BASE_URL env var) and the \`environment\` option are given. If you want to use the environment you must pass baseURL: null"`,
);

const client = new Intercom({
accessToken: 'My Access Token',
baseURL: null,
environment: 'production',
});
const client = new Intercom({ accessToken: 'My Access Token', baseURL: null, environment: 'us' });
expect(client.baseURL).toEqual('https://api.intercom.io');
});
});
Expand Down

0 comments on commit 8768954

Please sign in to comment.