This repository has been archived by the owner on Nov 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0c45030
Showing
16 changed files
with
1,473 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Lint | ||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: v1.42.0 | ||
- run: deno fmt --check . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { copy, walk } from 'jsr:@std/[email protected]'; | ||
|
||
/** cleanup */ | ||
|
||
try { | ||
await Deno.remove('dist', { recursive: true }); | ||
} finally { | ||
await Deno.mkdir('dist'); | ||
} | ||
|
||
/** install dependencies */ | ||
|
||
await (new Deno.Command('npm', { | ||
args: ['i', '-g', 'esbuild'], | ||
})).output(); | ||
|
||
/** copy files */ | ||
|
||
await copy('src', 'dist/src'); | ||
await copy('README.md', 'dist/README.md'); | ||
await copy('LICENSE', 'dist/LICENSE'); | ||
|
||
/** build javascript */ | ||
|
||
await (new Deno.Command('npx', { | ||
args: [ | ||
'esbuild', | ||
'./src/*', | ||
'./src/**/*', | ||
'--outdir=dist/dist', | ||
'--target=esnext', | ||
'--platform=node', | ||
], | ||
})).output(); | ||
|
||
async function transformFile(path: string) { | ||
let content = await Deno.readTextFile(path); | ||
content = content.replaceAll('.ts', '.js'); | ||
content = content.replace('jsr:@denosaurs/[email protected]', 'node:events'); | ||
await Deno.writeTextFile(path, content); | ||
} | ||
|
||
for await (const { isDirectory, isFile, path } of walk('dist/dist')) { | ||
if (isFile) await transformFile(path); | ||
if (isDirectory) { | ||
for await (const { isFile, path: newpath } of walk(path)) { | ||
if (isFile) await transformFile(newpath); | ||
} | ||
} | ||
} | ||
|
||
/** copy metadata */ | ||
|
||
const { version } = JSON.parse(Deno.readTextFileSync('deno.json')); | ||
|
||
const pkg = { | ||
'name': '@meower-media/api-client', | ||
'version': version, | ||
'description': 'A Meower API Client written in Typescript', | ||
'type': 'module', | ||
'main': 'dist/index.js', | ||
'types': 'src/index.ts', | ||
'repository': { | ||
'type': 'git', | ||
'url': 'https://github.com/meower-media-co/meower.js', | ||
}, | ||
'optionalDependencies': { | ||
'ws': '^8.13.0', | ||
}, | ||
'scripts': {}, | ||
}; | ||
|
||
Deno.writeTextFileSync('dist/package.json', JSON.stringify(pkg, null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Publish Package | ||
on: | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
id-token: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: v1.42.0 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
- run: deno publish | ||
- run: deno run -A .github/workflows/release.ts | ||
- run: npm publish --provenance --access public | ||
working-directory: dist | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2024 William Horning <[email protected]> and contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# api-client | ||
|
||
A Meower API Client written in Typescript. | ||
|
||
## installation | ||
|
||
install and import the package from your favorite source of packages: | ||
|
||
- @meower-media/api-client from npm | ||
- @meower/api-client from jsr | ||
- deno.land/x/meower-api-client on deno | ||
- esm.sh/jsr/@meower/api-client in browsers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "@meower/api-client", | ||
"version": "1.0.0-rc1", | ||
"exports": "./src/index.ts", | ||
"include": [ | ||
"src", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"fmt": { | ||
"lineWidth": 80, | ||
"proseWrap": "always", | ||
"semiColons": true, | ||
"useTabs": true, | ||
"singleQuote": true | ||
}, | ||
"lint": { | ||
"rules": { | ||
"include": [ | ||
"ban-untagged-todo", | ||
"default-param-last", | ||
"eqeqeq", | ||
"no-eval", | ||
"triple-slash-reference", | ||
"verbatim-module-syntax" | ||
] | ||
}, | ||
"exclude": [ | ||
".github/**/*" | ||
] | ||
}, | ||
"lock": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { rest_api } from './rest.ts'; | ||
import { socket } from './socket.ts'; | ||
|
||
/** options used by the client to login */ | ||
export interface client_login_options { | ||
/** username */ | ||
username: string; | ||
/** password or api token */ | ||
password: string; | ||
/** api url */ | ||
api_url: string; | ||
/** socket url */ | ||
socket_url: string; | ||
} | ||
|
||
/** options used by the client to signup */ | ||
export interface client_signup_options extends client_login_options { | ||
/** captcha response key */ | ||
captcha: string; | ||
} | ||
|
||
/** a meower api client written in typescript */ | ||
export class Client { | ||
/** access to the rest api */ | ||
api: rest_api; | ||
/** access to websocket events */ | ||
socket: socket; | ||
|
||
private constructor(api: rest_api, socket: socket) { | ||
this.api = api; | ||
this.socket = socket; | ||
} | ||
|
||
/** signup for an account and login */ | ||
static async signup( | ||
opts: client_signup_options, | ||
): Promise<Client> { | ||
const rest = await rest_api.signup( | ||
opts.username, | ||
opts.password, | ||
opts.captcha, | ||
opts.api_url, | ||
); | ||
|
||
const ws = await socket.connect({ ...opts, api_token: rest.api_token }); | ||
|
||
return new Client(rest, ws); | ||
} | ||
|
||
/** login to an account */ | ||
static async login(opts: client_login_options): Promise<Client> { | ||
const rest = await rest_api.login( | ||
opts.username, | ||
opts.password, | ||
opts.api_url, | ||
); | ||
|
||
const ws = await socket.connect({ ...opts, api_token: rest.api_token }); | ||
|
||
return new Client(rest, ws); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* interfaces to interact with the meower api | ||
*/ | ||
export * from './client.ts'; | ||
export * from './rest.ts'; | ||
export * from './socket.ts'; |
Oops, something went wrong.