chore: add docs, license and prepare for release (#4)

* chore: add initial readme and license info
* minor fix: remove colon from note
* some jsdocs
* update build action
* fix nx command on gh action
* specify remote origin as base in build
* update release info
* semantic release config
* rename auth headers
* chore: update package-lock.json
This commit is contained in:
Daniel Rochetti 2023-03-31 07:09:19 -07:00 committed by GitHub
parent a0e9d6e934
commit 1724bc37e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 6399 additions and 421 deletions

4
.commitlintrc.json Normal file
View File

@ -0,0 +1,4 @@
{
"extends": ["@commitlint/config-conventional"],
"rules": {}
}

View File

@ -9,24 +9,21 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x]
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version: '18.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Format check
run: npx nx affected --target=format --base=remotes/origin/${{ github.base_ref }}
- name: Lint
run: npx nx affected --target=lint --base=remotes/origin/${{ github.base_ref }}
- name: Build
uses: mansagroup/nrwl-nx-action@v3
with:
affected: 'true'
parallel: 1
targets: format,lint,build
run: npx nx affected --target=build --prod --base=remotes/origin/${{ github.base_ref }}

29
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,29 @@
name: Release
on:
push:
branches:
- main
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
scope: '@fal'
- name: Install dependencies
run: npm ci
- name: Publish to NPM
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: npx nx release client

4
.husky/commit-msg Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install commitlint --edit $1

7
.nxreleaserc.json Normal file
View File

@ -0,0 +1,7 @@
{
"changelog": true,
"npm": true,
"github": true,
"repositoryUrl": "https://github.com/fal-ai/serverless-js",
"branches": ["main"]
}

7
LICENSE Normal file
View File

@ -0,0 +1,7 @@
Copyright 2023 https://fal.ai
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.

69
README.md Normal file
View File

@ -0,0 +1,69 @@
# The fal-serverless JS Client
![NPM](https://img.shields.io/npm/v/@fal/serverless-js)
![License](https://img.shields.io/github/license/fal-ai/serverless-js)
![Build](https://img.shields.io/github/actions/workflow/status/fal-ai/serverless-js/build)
## About the project
The fal-serverless JS/TS Client is a powerful and easy-to-use JavaScript and TypeScript library that allows you to effortlessly integrate and run your fal serverless functions in your Web, Node.js and React Native applications.
The project is written in TypeScript, so developers get type-safety out of the box.
## Getting Started
The serverless-js library is a client for the fal serverless Python functions. Check the [quickstart guide](https://docs.fal.ai/fal-serverless/quickstart) in order to create your functions.
### Library
The client library is designed as a lightweight layer on top of the platform standards, such as `fetch` and `WebSocket`, ensuring smooth integration with your existing codebase.
It also handle platform differences, so it work seamlessly across different JS runtimes.
> **Note**
>
> Make sure you followed the [fal-serverless getting started]() so you get your credentials and register your functions.
1. First you need to configure your credentials:
```ts
import * as fal from '@fal/serverless-js';
fal.config({
credentials: {
userId: 'USER_ID',
keyId: 'KEY_ID',
keySecret: 'KEY_SECRET',
},
});
```
2. Get your function id and run it:
```ts
const result = await fal.run('my-function-id');
```
The result type depends on the result of your Python function
## Roadmap
See the [open feature requests](https://github.com/fal-ai/serverless-js/labels/enhancement) for a list of proposed features and join the discussion.
## Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.
1. Make sure you read our [Code of Conduct](https://github.com/fal-ai/serverless-js/blob/main/CODE_OF_CONDUCT.md)
2. Fork the project and clone your fork
3. Setup the local environment with `npm install`
4. Create a feature branch (`git checkout -b feature/add-cool-thing`) or a bugfix branch (`git checkout -b fix/smash-that-bug`)
5. Commit the changes (`git commit -m 'feat(client): added a cool thing'`) - use [conventional commits](https://conventionalcommits.org)
6. Push to the branch (`git push --set-upstream origin feature/add-cool-thing`)
7. Open a Pull Request
Check the [good first issue queue](https://github.com/fal-ai/serverless-js/labels/good+first+issue), your contribution will be welcome!
## License
Distributed under the MIT License. See [LICENSE](https://github.com/fal-ai/serverless-js/blob/main/LICENSE) for more information.

View File

@ -1,9 +1,17 @@
{
"name": "@fal/serverless-client",
"version": "0.0.1",
"description": "The fal serverless JS/TS client",
"version": "0.0.0-semantic-release",
"repository": {
"type": "git",
"url": "https://github.com/fal-ai/serverless-js",
"url": "https://github.com/fal-ai/serverless-js.git",
"directory": "libs/client"
}
},
"keywords": [
"fal",
"serverless",
"client",
"ai",
"ml"
]
}

View File

@ -35,6 +35,9 @@
"codeCoverage": true
}
}
},
"release": {
"executor": "@theunderscorer/nx-semantic-release:semantic-release"
}
},
"tags": []

View File

@ -3,15 +3,15 @@ import { getConfig } from './config';
import { getUserAgent, isBrowser } from './runtime';
/**
* An event contract for progress updates from the server function.
* The function input and other configuration when running
* the function, such as the HTTP method to use.
*/
export interface ProgressEvent<T> {
readonly progress: number;
readonly partialData: T | undefined;
}
type RunOptions<Input> = {
readonly input?: Input;
/**
* The HTTP method, defaults to `post`;
*/
readonly method?: 'get' | 'post' | 'put' | 'delete';
};
@ -36,8 +36,8 @@ export async function run<Input, Output>(
{
method,
headers: {
'X-Koldstart-Key-Id': credentials.keyId,
'X-Koldstart-Key-Secret': credentials.keySecret,
'X-Fal-Key-Id': credentials.keyId,
'X-Fal-Key-Secret': credentials.keySecret,
Accept: 'application/json',
'Content-Type': 'application/json',
...userAgent,
@ -64,6 +64,14 @@ export async function run<Input, Output>(
return response.text() as Promise<Output>;
}
/**
* An event contract for progress updates from the server function.
*/
export interface ProgressEvent<T> {
readonly progress: number;
readonly partialData: T | undefined;
}
/**
* Represents a result of a remote fal serverless function call.
*

View File

@ -1,2 +1,4 @@
export { config, Credentials } from './config';
export { FunctionExecution, ProgressEvent, run } from './function';
export type { Credentials } from './config';
export { config } from './config';
export type { FunctionExecution, ProgressEvent } from './function';
export { run } from './function';

6629
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,8 @@
"scripts": {
"start": "nx serve",
"build": "nx build",
"test": "nx test"
"test": "nx test",
"prepare": "husky install"
},
"private": true,
"dependencies": {
@ -26,6 +27,8 @@
"tslib": "^2.3.0"
},
"devDependencies": {
"@commitlint/cli": "^17.0.0",
"@commitlint/config-conventional": "^17.0.0",
"@nrwl/cli": "15.7.2",
"@nrwl/cypress": "15.7.2",
"@nrwl/eslint-plugin-nx": "15.7.2",
@ -38,6 +41,7 @@
"@nrwl/web": "15.7.2",
"@nrwl/workspace": "15.7.2",
"@testing-library/react": "13.4.0",
"@theunderscorer/nx-semantic-release": "^2.2.1",
"@types/google-protobuf": "^3.15.6",
"@types/jest": "28.1.1",
"@types/node": "16.11.7",
@ -57,6 +61,7 @@
"eslint-plugin-react": "^7.31.8",
"eslint-plugin-react-hooks": "^4.6.0",
"fs-extra": "^11.1.0",
"husky": "^8.0.0",
"jest": "28.1.1",
"jest-environment-jsdom": "28.1.1",
"nx": "15.7.2",