Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
williamhorning committed Jul 7, 2024
0 parents commit 0c45030
Show file tree
Hide file tree
Showing 16 changed files with 1,473 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/lint.yml
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 .
73 changes: 73 additions & 0 deletions .github/workflows/release.ts
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));
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
19 changes: 19 additions & 0 deletions LICENSE
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.
12 changes: 12 additions & 0 deletions README.md
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
33 changes: 33 additions & 0 deletions deno.json
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
}
62 changes: 62 additions & 0 deletions src/api/client.ts
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);
}
}
6 changes: 6 additions & 0 deletions src/api/index.ts
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';
Loading

0 comments on commit 0c45030

Please sign in to comment.