Skip to content

Commit

Permalink
Add option to change base url for API requests (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillsud authored Nov 7, 2023
1 parent da8e3a1 commit eeb90f0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## [2.1.0]

- added option to change base url for PAI requests

## [2.0.2]

- fixed cursor pagination for `getAllTeamMembers` ([#224](https://github.com/miroapp/api-clients/issues/224) by [Mahito](https://github.com/Mahito))
-

## [2.0.1]

- fixed cursor pagination for `getAllOrganizationMembers` ([#209](https://github.com/miroapp/api-clients/pull/209) by [Mahito](https://github.com/Mahito))
Expand Down
11 changes: 8 additions & 3 deletions packages/miro-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class Miro {
storage: Storage
logger?: (l: any) => void
httpTimeout?: number
basePath: string

/**
* Initializes the Miro API with the given client id and client secret
Expand All @@ -28,6 +29,7 @@ export class Miro {
this.storage = opts.storage || new InMemoryStorage()
this.logger = opts.logger || (process.env.MIRO_DEBUG ? console.log : undefined)
this.httpTimeout = opts.httpTimeout
this.basePath = opts.basePath || defaultBasePath

if (!this.clientId) {
throw new Error('miro-api: MIRO_CLIENT_ID or passing options.clientId is required')
Expand All @@ -47,7 +49,7 @@ export class Miro {
* Returns an instance of the highlevel Miro API for the given user id
*/
as(userId: ExternalUserId): MiroApi {
return new MiroApi(async () => await this.getAccessToken(userId), undefined, this.logger, this.httpTimeout)
return new MiroApi(async () => await this.getAccessToken(userId), this.basePath, this.logger, this.httpTimeout)
}

/**
Expand All @@ -65,7 +67,7 @@ export class Miro {
* Returns a URL that user should be redirected to in order to authorize the application, accepts an optional state argument and a teamId that will be used as a default
*/
getAuthUrl(state?: string, teamId?: string): string {
const authorizeUrl = new URL('/oauth/authorize', defaultBasePath.replace('api.', ''))
const authorizeUrl = new URL('/oauth/authorize', this.basePath.replace('api.', ''))
authorizeUrl.search = new URLSearchParams({
response_type: 'code',
client_id: this.clientId,
Expand Down Expand Up @@ -185,7 +187,7 @@ export interface MiroOptions {
/** App Client secret. Defaults to MIRO_CLIENT_SECRET environment variable */
clientSecret?: string

/** App redirect URL, should match the one configued in the Miro App settings page. Defaults to MIRO_REDIRECT_URL environment variable */
/** App redirect URL, should match the one configured in the Miro App settings page. Defaults to MIRO_REDIRECT_URL environment variable */
redirectUrl?: string

/** Implementation of storage to use for access and refresh tokens */
Expand All @@ -196,6 +198,9 @@ export interface MiroOptions {

/** Client will abort HTTP requests that last longer than this number of miliseconds. Default is 5000ms. */
httpTimeout?: number

/** Base path **/
basePath?: string
}

import {Api as HighlevelApi} from './highlevel/index'
Expand Down
2 changes: 1 addition & 1 deletion packages/miro-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mirohq/miro-api",
"version": "2.0.2",
"version": "2.1.0",
"description": "Node.js client for the Miro REST API",
"repository": {
"type": "git",
Expand Down

0 comments on commit eeb90f0

Please sign in to comment.