Skip to content

Commit

Permalink
Merge branch 'master' into bun-sh
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatOneCalculator authored Oct 1, 2023
2 parents 7bad8a0 + abab2db commit c6c3e0a
Show file tree
Hide file tree
Showing 29 changed files with 1,871 additions and 1,796 deletions.
31 changes: 30 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,35 @@ jobs:
- name: Testing
run: |
yarn workspace megalodon run test
example:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x, 19.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: |
yarn install
- name: Build
run: |
yarn workspace megalodon run build
- name: Browser example
run: |
yarn workspace browser run build
- name: Typescript example
env:
MASTODON_URL: https://fedibird.com
PLEROMA_URL: https://pleroma.io
FIREFISH_URL: https://cybre.club
FRIENDICA_URL: https://squeet.me
run: |
yarn workspace example run build
Expand All @@ -61,4 +86,8 @@ jobs:
- name: Browser example (Bun)
run: cd example/browser && bun run build:bun
- name: Typescript example (Bun)
run: cd example/typescript && bun run build
run: cd example/typescript && bun run build
node example/typescript/dist/mastodon/instance.js
node example/typescript/dist/pleroma/instance.js
node example/typescript/dist/firefish/instance.js
node example/typescript/dist/friendica/instance.js
20 changes: 0 additions & 20 deletions .swcrc

This file was deleted.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ const client = generator('mastodon', BASE_URL)

client.registerApp('Test App')
.then(appData => {
clientId = appData.clientId
clientSecret = appData.clientSecret
clientId = appData.client_id
clientSecret = appData.client_secret
console.log('Authorization URL is generated.')
console.log(appData.url)
})
Expand All @@ -187,8 +187,8 @@ const code = '...' // Authorization code

client.fetchAccessToken(clientId, clientSecret, code)
.then((tokenData: OAuth.TokenData) => {
console.log(tokenData.accessToken)
console.log(tokenData.refreshToken)
console.log(tokenData.access_token)
console.log(tokenData.refresh_token)
})
.catch((err: Error) => console.error(err))
```
Expand Down
2 changes: 0 additions & 2 deletions example/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"megalodon": "*"
},
"devDependencies": {
"@swc/core": "^1.3.87",
"assert": "^2.1.0",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
Expand All @@ -26,7 +25,6 @@
"querystring-es3": "^0.2.1",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"swc-loader": "^0.2.3",
"ts-loader": "^9.4.4",
"typescript": "5.2.2",
"url": "^0.11.3",
Expand Down
22 changes: 3 additions & 19 deletions example/browser/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var path = require('path');
var webpack = require('webpack');
var path = require('path')
var webpack = require('webpack')

module.exports = {
entry: './src/index.ts',
Expand All @@ -11,9 +11,6 @@ module.exports = {
devtool: 'source-map',
resolve: {
extensions: ['.ts', '.js'],
alias: {
megalodon: path.resolve(__dirname, '../../megalodon/lib/index.js'), // adjust the path if necessary
},
fallback: {
net: false,
tls: false,
Expand All @@ -35,20 +32,7 @@ module.exports = {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript',
tsx: false,
}
}
}
}
]
loader: 'ts-loader'
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion example/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "4.0.0",
"private": true,
"scripts": {
"build": "swc ./src -d dist --source-maps",
"build": "tsc -p ./",
"lint": "eslint --ext .js,.ts src"
},
"author": "h3poteto",
Expand Down
9 changes: 4 additions & 5 deletions example/typescript/src/firefish/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ const client = new Firefish(BASE_URL)
client
.registerApp('Test App')
.then(appData => {
clientId = appData.clientId
clientSecret = appData.clientSecret
clientId = appData.client_id
clientSecret = appData.client_secret
console.log('\napp_secret_key:')
console.log(clientSecret)
console.log('Authorization URL is generated.')
console.log(appData.url)
console.log()
Expand All @@ -38,9 +37,9 @@ client
})
.then((tokenData: OAuth.TokenData) => {
console.log('\naccess_token:')
console.log(tokenData.accessToken)
console.log(tokenData.access_token)
console.log('\nrefresh_token:')
console.log(tokenData.refreshToken)
console.log(tokenData.refresh_token)
console.log()
})
.catch((err: any) => {
Expand Down
11 changes: 11 additions & 0 deletions example/typescript/src/firefish/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import generator, { MegalodonInterface } from 'megalodon'

const BASE_URL: string = process.env.FIREFISH_URL!
const access_token: string = process.env.FIREFISH_ACCESS_TOKEN!

const client: MegalodonInterface = generator('firefish', BASE_URL, access_token)

client
.search('h3poteto')
.then(res => console.log(res.data))
.catch(err => console.error(err))
12 changes: 12 additions & 0 deletions example/typescript/src/friendica/instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import generator, { Entity, Response } from 'megalodon'

const BASE_URL = process.env.FRIENDICA_URL!

const client = generator('friendica', BASE_URL)

client
.getInstance()
.then((res: Response<Entity.Instance>) => {
console.log(res.data)
})
.catch(err => console.error(err))
8 changes: 4 additions & 4 deletions example/typescript/src/mastodon/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ client
scopes: SCOPES
})
.then(appData => {
clientId = appData.clientId
clientSecret = appData.clientSecret
clientId = appData.client_id
clientSecret = appData.client_secret
console.log('Authorization URL is generated.')
console.log(appData.url)
console.log()
Expand All @@ -36,9 +36,9 @@ client
})
.then((tokenData: OAuth.TokenData) => {
console.log('\naccess_token:')
console.log(tokenData.accessToken)
console.log(tokenData.access_token)
console.log('\nrefresh_token:')
console.log(tokenData.refreshToken)
console.log(tokenData.refresh_token)
console.log()
})
.catch((err: Error) => console.error(err))
2 changes: 1 addition & 1 deletion example/typescript/src/mastodon/instance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import generator, { Entity, Response } from 'megalodon'

const BASE_URL: string = 'http://fedibird.com'
const BASE_URL: string = process.env.MASTODON_URL!

const client = generator('mastodon', BASE_URL)

Expand Down
8 changes: 4 additions & 4 deletions example/typescript/src/pleroma/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ client
scopes: SCOPES
})
.then(appData => {
clientId = appData.clientId
clientSecret = appData.clientSecret
clientId = appData.client_id
clientSecret = appData.client_secret
console.log('Authorization URL is generated.')
console.log(appData.url)
console.log()
Expand All @@ -36,9 +36,9 @@ client
})
.then((tokenData: OAuth.TokenData) => {
console.log('\naccess_token:')
console.log(tokenData.accessToken)
console.log(tokenData.access_token)
console.log('\nrefresh_token:')
console.log(tokenData.refreshToken)
console.log(tokenData.refresh_token)
console.log()
})
.catch((err: Error) => console.error(err))
2 changes: 1 addition & 1 deletion example/typescript/src/pleroma/instance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import generator, { Entity, Response } from 'megalodon'

const BASE_URL: string = 'http://pleroma.io'
const BASE_URL: string = process.env.PLEROMA_URL!

const client = generator('pleroma', BASE_URL)

Expand Down
20 changes: 0 additions & 20 deletions megalodon/.swcrc

This file was deleted.

17 changes: 6 additions & 11 deletions megalodon/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "megalodon",
"version": "8.0.1",
"version": "8.1.1",
"description": "Mastodon API client for node.js and browser",
"main": "./lib/src/index.js",
"typings": "./lib/src/index.d.ts",
"scripts": {
"build": "swc ./src -d ./lib",
"build:bun": "bun build ./src --outdir=lib --minify --target=node",
"build": "tsc -p ./",
"lint": "eslint --ext .js,.ts src",
"doc": "typedoc --out ../docs ./src",
"test": "NODE_ENV=test jest -u --maxWorkers=3"
Expand Down Expand Up @@ -45,20 +45,17 @@
],
"preset": "ts-jest/presets/default",
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "tsconfig.json"
}
]
"^.+\\.(ts|tsx)$": ["ts-jest", {
"tsconfig": "tsconfig.json"
}]
},
"testEnvironment": "node"
},
"homepage": "https://github.com/h3poteto/megalodon#readme",
"dependencies": {
"@types/oauth": "^0.9.2",
"@types/ws": "^8.5.5",
"axios": "1.5.0",
"axios": "1.5.1",
"dayjs": "^1.11.10",
"form-data": "^4.0.0",
"https-proxy-agent": "^7.0.2",
Expand All @@ -71,8 +68,6 @@
"ws": "8.14.2"
},
"devDependencies": {
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.87",
"@types/core-js": "^2.5.6",
"@types/form-data": "^2.5.0",
"@types/jest": "^29.5.5",
Expand Down
Loading

0 comments on commit c6c3e0a

Please sign in to comment.