Skip to content

Commit

Permalink
clients/docs: add sdk client documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
emilwidlund committed May 23, 2024
1 parent 4532a4a commit 9f4e64b
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
104 changes: 104 additions & 0 deletions clients/apps/web/src/app/docs/(mdx)/api-reference/polar-sdk/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import BrowserCallout from '@/components/Feed/Markdown/Callout/BrowserCallout';

# Polar SDK
The Polar SDK is a TypeScript library that provides a high-level API for interacting with the Polar platform. The API client is automatically generated from our OpenAPI implementation, making it up-to-date with the server-side API.

## Installation
The SDK is available from NPM. To install it, run:

```bash
pnpm install @polar-sh/sdk
```

### Configuring the Polar Client
In order to make requests with the Polar client, you need to provide an access key in the form of a Bearer token when making your requsts.

You can create personal access tokens in your [Polar settings](https://app.polar.sh/settings).

```typescript
import {PolarAPI, Configuration} from '@polar-sh/sdk';

const polar = new PolarAPI(
new Configuration({
headers: {
Authorization: `Bearer ${process.env.POLAR_ACCESS_TOKEN}`
}
})
);
```

<BrowserCallout type="CAUTION">
Remember to keep your access token secure and never expose it in client-side code.

If you are using the Polar SDK in a server-side application, you can store your access token in an environment variable and access it using `process.env.POLAR_ACCESS_TOKEN`.
</BrowserCallout>

## Examples

### Issues looking for funding
You can easily retrieve issues looking for funding using the Funding-service.

```typescript
import {
Configuration,
ListFundingSortBy,
Platforms,
PolarAPI,
} from '@polar-sh/sdk'

const polar = new PolarAPI(new Configuration())

const issuesFunding = await polar.funding.search({
platform: Platforms.GITHUB,
organizationName: '<MY_GITHUB_ORGANIZATION_NAME>',
badged: true,
closed: false,
sorting: [
ListFundingSortBy.MOST_FUNDED,
ListFundingSortBy.MOST_ENGAGEMENT,
ListFundingSortBy.NEWEST,
],
limit: 20,
})
```

### Issue data from GitHub Issue
Retrieve Polar data about a given GitHub issue.

```typescript
import { Configuration, PolarAPI } from '@polar-sh/sdk'

const polar = new PolarAPI(
new Configuration()
);

const params = {
organization: 'polarsource',
repo: 'polar',
number: 900,
}

const issue = await polar.issues.lookup({
externalUrl: `https://github.com/${params.organization}/${params.repo}/issues/${params.number}`,
})
```

### Add Polar badge to a GitHub issue
Adds a Polar badge to a given GitHub issue.

```typescript
import { PolarAPI, Configuration } from '@polar-sh/sdk';

const polar = new PolarAPI(
new Configuration({
headers: {
Authorization: `Bearer ${process.env.POLAR_ACCESS_TOKEN}`
}
})
);

await polar.issues.addPolarBadge({
id: '<ISSUE_ID>',
})
```

3 changes: 3 additions & 0 deletions clients/apps/web/src/components/Documentation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ const APISections = () => {
<NaviagtionItem href="/docs/api-reference/introduction">
Introduction
</NaviagtionItem>
<NaviagtionItem href="/docs/api-reference/polar-sdk">
Polar SDK
</NaviagtionItem>
<NaviagtionItem href="/docs/api-reference/github-actions">
GitHub Actions
</NaviagtionItem>
Expand Down

0 comments on commit 9f4e64b

Please sign in to comment.