Skip to content

Commit

Permalink
Add npm-publish github action
Browse files Browse the repository at this point in the history
Also fixes the examples in README
  • Loading branch information
Capster committed Oct 7, 2023
1 parent 6776655 commit c32c294
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Documentation Generation
name: Genereate Docs and Deploy to Pages
on:
push:
branches:
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish to NPM

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
uses: bahmutov/npm-install@v1

- name: Build a package
run: npm run build

- name: Publish a package
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Build a package
on:
pull_request:
branches:
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ import { client } from 'node-shikimori';

const shikimori = client({});

shikimori.animes.byId({
const result = await shikimori.animes.byId({
id: 1
}).then(console.log);
});

console.log(result);
```

## Authorization
Expand All @@ -62,20 +64,21 @@ const { getAccessToken } = auth({
client_secret: 'YOUR_CLIENT_SECTET',
});

const accessToken = getAccessToken('YOUR_AUTH_CODE');
const accessToken = await getAccessToken('YOUR_AUTH_CODE');
```

4. **Use access token to access protected resources:** Finally, your application can use the access token to access the user's protected resources. Be sure to handle any errors or expired tokens gracefully.
```ts
const shikimori = client();
shikimori.setAccessToken(YOUR_ACCESS_TOKEN);

shikimori.users.whoami().then(console.log);
const currentUser = await shikimori.users.whoami();
console.log(currentUser)
```

5.**Refresh access token:** Access tokens have a limited lifespan of **1 day**, so your application will need to refresh them periodically to maintain access to the user's resources. To do this use a `refreshAccessToken` function with the refresh token. Shikimori will respond with a new access token and refresh token that your application can use to continue accessing the user's resources.
```ts
const newAccessToken = refreshAccessToken('YOUR_REFRESH_TOKEN');
const newAccessToken = await refreshAccessToken('YOUR_REFRESH_TOKEN');
```

## Contribution
Expand Down

0 comments on commit c32c294

Please sign in to comment.