diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index abb2ff7ac..e9347dc5c 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -135,6 +135,8 @@ jobs: path: examples/apps/${{ matrix.example }} # Install dependencies in the example repo + # Don't use "npm ci", "--immutable" etc., as example repos won't be + # shipped with lock files. - name: Install example dependencies run: ni working-directory: examples/apps/${{ matrix.example }} diff --git a/README.md b/README.md deleted file mode 100644 index ec375698f..000000000 --- a/README.md +++ /dev/null @@ -1,198 +0,0 @@ -
-
- -
-
-

- Serverless event-driven queues, background jobs, and scheduled jobs for Typescript.
- Works with any framework and platform. -

- Read the documentation and get started in minutes. -
-

- - - -
- - - -

-
- -
- -On _any_ serverless platform ([Next.js](https://www.inngest.com/docs/sdk/serve#framework-next-js), [Deno Deploy](https://www.inngest.com/docs/sdk/serve#framework-fresh-deno), [RedwoodJS](https://www.inngest.com/docs/sdk/serve#framework-redwood), [AWS Lambda](https://www.inngest.com/docs/sdk/serve#framework-aws-lambda), and [anything else](https://www.inngest.com/docs/sdk/serve#custom-frameworks)) and with no extra infrastructure: - -- โšก Write background jobs -- ๐Ÿ• Create scheduled & cron jobs -- โ™ป๏ธ Build serverless queues -- ๐Ÿชœ Write complex step functions -- ๐Ÿš˜ Build serverless event-driven systems -- ๐Ÿช Reliably respond to webhooks, with retries & payloads stored for history - -๐Ÿ‘‹ _Have a question or feature request? [Join our Discord](https://www.inngest.com/discord)!_ - -
- -

-Getting started ยท -Features ยท -Contributing ยท -Documentation -

- -
- -## Getting started - -
- -Install Inngest: - -```bash -npm install inngest # or yarn add inngest -``` - -### Writing functions - -Write serverless functions and background jobs right in your own code: - -```ts -import { Inngest } from "inngest"; - -const inngest = new Inngest({ name: "My App" }); - -// This function will be invoked by Inngest via HTTP any time -// the "app/user.signup" event is sent to to Inngest -export default inngest.createFunction( - { name: "User onboarding communication" }, - { event: "app/user.signup" }, - async ({ event, step }) => { - await step.run("Send welcome email", async () => { - await sendEmail({ - email: event.data.email, - template: "welcome", - }); - }); - } -); -``` - -- Functions are triggered by events which can be sent via this SDK, webhooks, integrations, or with a simple HTTP request. -- When a matching event is received, Inngest invokes the function automatically, with built-in retries. - -### Serving your functions - -Inngest invokes functions via HTTP, so you need to _serve_ them using an adapter for the framework of your choice. [See all frameworks here in our docs](https://www.inngest.com/docs/sdk/serve?ref=github-inngest-js-readme). Here is an example using the Next.js serve handler: - -```ts -// /pages/api/inngest.ts -import { Inngest } from "inngest"; -// See the "inngest/next" adapter imported here: -import { serve } from "inngest/next"; -import myFunction from "../userOnboardingCOmmunication"; // see above function - -// You can create this in a single file and import where it's needed -const inngest = new Inngest({ name: "My App" }); - -// Securely serve your Inngest functions for remote invocation: -export default serve(inngest, [myFunction]); -``` - -### Sending events to trigger functions - -```ts -// Send events -import { Inngest } from "inngest"; -const inngest = new Inngest({ name: "My App" }); - -// This will run the function above automatically, in the background -inngest.send("app/user.signup", { - data: { email: "text@example.com", user_id: "12345" }, -}); -``` - -- Events can trigger one or more functions automatically, enabling you to fan-out work. -- Inngest stores a history of all events for observability, testing, and replay. - -
- -## Features - -- **Fully serverless:** Run background jobs, scheduled functions, and build event-driven systems without any servers, state, or setup -- **Works with your framework**: Works with [Next.js, Redwood, Express, Cloudflare Pages, Nuxt, Fresh (Deno), and Remix](https://www.inngest.com/docs/sdk/serve?ref=github-inngest-js-readme) -- **Deploy anywhere**: Keep [deploying to your existing platform](https://www.inngest.com/docs/deploy?ref=github-inngest-js-readme): Vercel, Netlify, Cloudflare, Deno, Digital Ocean, etc. -- **Use your existing code:** Write functions within your current project and repo -- **Fully typed**: Event schemas, versioning, and governance out of the box -- **Observable**: A full UI for managing and inspecting your functions - -
- -## Contributing - -Prerequisites: - -1. Install [pnpm](https://pnpm.io/installation) -2. Install [Volta](https://volta.sh/) - -Clone the repository, then: - -```sh -cd packages/inngest -pnpm run dev # install dependencies, build/lint/test -``` - -> When making a pull request, make sure to commit the changed `etc/inngest.api.md` file; this is a generated types/docs file that will highlight changes to the exposed API. - -### Testing changes locally - -To test changes with other local repos, you can package the library and install the resulting file directly, including shipping it with an application. This is a nice way to generate and ship snapshot/test versions of the library to test locally and in production environments without requiring releasing to npm. - -```sh -# in this repo -cd packages/inngest -pnpm run local:pack -cp ./inngest.tgz ../some-other-repo-root - -# in another repo -npm install ./inngest.tgz -``` - -Some platforms require manually installing the package again at build time to properly link dependencies, so you may have to change your `yarn build` script to be prefixed with this install, e.g.: - -```sh -npm install ./inngest.tgz && framework dev -``` - -### Releasing - -To release to production, we use [Changesets](https://github.com/changesets/changesets). This means that releasing and changelog generation is all managed through PRs, where a bot will guide you through the process of announcing changes in PRs and releasing them once merged to `main`. - -#### Legacy versions - -Merging and releasing to previous major versions of the SDK is also supported. - -- Add a `backport v*.x` label (e.g. `backport v1.x`) to a PR to have a backport PR generated when the initial PR is merged. -- Merging into a `v*.x` branch creates a release PR (named **Release v1.x**, for example) the same as the `main` branch. Simply merge to release. - -#### Snapshot versions - -If a local `inngest.tgz` isn't ideal, we can release a tagged version to npm. For now, this is relatively manual. For this, please ensure you are in an open PR branch for observability. - -Decide on the "tag" you will be publishing to, which will dictate how the user installs the snapshot, e.g. if your tag is `beta`, the user will install using `inngest@beta`. - -You can see the currently available tags on the [`inngest` npm page](https://www.npmjs.com/package/inngest?activeTab=versions). - -> **NEVER** use the `latest` tag, and **NEVER** run `npm publish` without specifying `--tag`. - -If the current active version is `v1.1.1`, this is a minor release, and our tag is `foo`, we'd do: - -```sh -cd packages/inngest -pnpm version v1.2.0-foo.1 -pnpm run build -pnpm publish --access public --tag foo -``` - -You can iterate the final number for each extra snapshot you need to do on a branch. diff --git a/README.md b/README.md new file mode 120000 index 000000000..d05d572b4 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +./packages/inngest/README.md \ No newline at end of file diff --git a/packages/inngest/CHANGELOG.md b/packages/inngest/CHANGELOG.md index 1ce8ebef5..70e67f255 100644 --- a/packages/inngest/CHANGELOG.md +++ b/packages/inngest/CHANGELOG.md @@ -1,5 +1,15 @@ # inngest +## 2.4.0 + +### Minor Changes + +- 6cb6719: Allow filtering of events within triggers + +### Patch Changes + +- 55c889c: Expose raw error message if status is unknown + ## 2.3.0 ### Minor Changes diff --git a/packages/inngest/package.json b/packages/inngest/package.json index 0ca76d111..a061e5027 100644 --- a/packages/inngest/package.json +++ b/packages/inngest/package.json @@ -1,6 +1,6 @@ { "name": "inngest", - "version": "2.3.0", + "version": "2.4.0", "description": "Official SDK for Inngest.com", "main": "./index.js", "types": "./index.d.ts", diff --git a/packages/inngest/src/components/Inngest.ts b/packages/inngest/src/components/Inngest.ts index fbd595d37..0b1c2eee1 100644 --- a/packages/inngest/src/components/Inngest.ts +++ b/packages/inngest/src/components/Inngest.ts @@ -244,7 +244,11 @@ export class Inngest { case 500: errorMessage = "Internal server error"; break; + default: + errorMessage = await response.text(); + break; } + return new Error(`Inngest API Error: ${response.status} ${errorMessage}`); } @@ -483,10 +487,23 @@ export class Inngest { keyof EventsFromOpts & string >; + let sanitizedTrigger: FunctionTrigger & string>; + + if (typeof trigger === "string") { + sanitizedTrigger = { event: trigger }; + } else if (trigger.event) { + sanitizedTrigger = { + event: trigger.event, + expression: trigger.if, + }; + } else { + sanitizedTrigger = trigger; + } + return new InngestFunction( this, sanitizedOpts, - typeof trigger === "string" ? { event: trigger } : trigger, + sanitizedTrigger, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any handler as any ); diff --git a/packages/inngest/src/types.ts b/packages/inngest/src/types.ts index 4d2ac4b37..834fe866a 100644 --- a/packages/inngest/src/types.ts +++ b/packages/inngest/src/types.ts @@ -606,6 +606,7 @@ export type TriggerOptions = | StrictUnion< | { event: T; + if?: string; } | { cron: string;