New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

inngest

Package Overview
Dependencies
Maintainers
2
Versions
681
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inngest - npm Package Compare versions

Comparing version 0.8.5 to 0.8.6-beta.1

components/InngestCommHandler.d.ts

2

cloudflare.d.ts

@@ -1,2 +0,2 @@

import { ServeHandler } from "./express";
import { ServeHandler } from "./components/InngestCommHandler";
/**

@@ -3,0 +3,0 @@ * In Cloudflare, serve and register any declared functions with Inngest, making

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serve = void 0;
const zod_1 = require("zod");
const express_1 = require("./express");
const InngestCommHandler_1 = require("./components/InngestCommHandler");
const consts_1 = require("./helpers/consts");
const devserver_1 = require("./helpers/devserver");
const landing_1 = require("./landing");
class CloudflareCommHandler extends express_1.InngestCommHandler {
constructor() {
super(...arguments);
this.frameworkName = "cloudflare-pages";
}
createHandler() {
return async ({ request: req, env, }) => {
const headers = { "x-inngest-sdk": this.sdkHeader.join("") };
let reqUrl;
let isIntrospection;
try {
reqUrl = this.reqUrl(req.url, `https://${req.headers.get("host") || ""}`);
isIntrospection = reqUrl.searchParams.has(consts_1.queryKeys.Introspect);
reqUrl.searchParams.delete(consts_1.queryKeys.Introspect);
}
catch (err) {
return new Response(JSON.stringify(err), {
status: 500,
headers,
});
}
if (!this.signingKey && env[consts_1.envKeys.SigningKey]) {
this.signingKey = env[consts_1.envKeys.SigningKey];
}
this._isProd = env.CF_PAGES === "1" || env.ENVIRONMENT === "production";
switch (req.method) {
case "GET": {
const showLandingPage = this.shouldShowLandingPage(env[consts_1.envKeys.LandingPage]);
if (this._isProd || !showLandingPage)
break;
if (isIntrospection) {
const introspection = Object.assign(Object.assign({}, this.registerBody(reqUrl)), { devServerURL: (0, devserver_1.devServerUrl)(env[consts_1.envKeys.DevServerUrl]).href, hasSigningKey: Boolean(this.signingKey) });
return new Response(JSON.stringify(introspection), {
status: 200,
headers,
});
}
// Grab landing page and serve
return new Response(landing_1.landing, {
status: 200,
headers: Object.assign(Object.assign({}, headers), { "content-type": "text/html; charset=utf-8" }),
});
}
case "PUT": {
// Push config to Inngest.
const { status, message } = await this.register(reqUrl, env[consts_1.envKeys.DevServerUrl]);
return new Response(JSON.stringify({ message }), { status, headers });
}
case "POST": {
// Inngest is trying to run a step; confirm signed and run.
const { fnId, stepId } = zod_1.z
.object({
fnId: zod_1.z.string().min(1),
stepId: zod_1.z.string().min(1),
})
.parse({
fnId: reqUrl.searchParams.get(consts_1.queryKeys.FnId),
stepId: reqUrl.searchParams.get(consts_1.queryKeys.StepId),
});
const stepRes = await this.runStep(fnId, stepId, await req.json());
if (stepRes.status === 500) {
return new Response(JSON.stringify(stepRes.error), {
status: stepRes.status,
headers,
});
}
return new Response(JSON.stringify(stepRes.body), {
status: stepRes.status,
headers,
});
}
}
return new Response(null, { status: 405, headers });
};
}
}
/**

@@ -92,5 +13,52 @@ * In Cloudflare, serve and register any declared functions with Inngest, making

const serve = (nameOrInngest, fns, opts) => {
return (0, express_1.serve)(new CloudflareCommHandler(nameOrInngest, fns, Object.assign({ fetch: fetch.bind(globalThis) }, opts)));
const handler = new InngestCommHandler_1.InngestCommHandler("cloudflare-pages", nameOrInngest, fns, Object.assign({
/**
* Assume that we want to override the `fetch` implementation with the one
* globally available in the Cloudflare env. Specifying it here will
* ensure we avoid trying to load a Node-compatible version later.
*/
fetch: fetch.bind(globalThis) }, opts), ({ request: req, env, }) => {
const url = new URL(req.url, `https://${req.headers.get("host") || ""}`);
const isProduction = env.CF_PAGES === "1" || env.ENVIRONMENT === "production";
return {
view: () => {
if (req.method === "GET") {
return {
url,
env,
isIntrospection: url.searchParams.has(consts_1.queryKeys.Introspect),
isProduction,
};
}
},
register: () => {
if (req.method === "PUT") {
return {
env,
url,
isProduction,
};
}
},
run: async () => {
if (req.method === "POST") {
return {
fnId: url.searchParams.get(consts_1.queryKeys.FnId),
data: (await req.json()),
env,
isProduction,
url,
};
}
},
};
}, ({ body, status, headers }) => {
return new Response(body, {
status,
headers,
});
});
return handler.createHandler();
};
exports.serve = serve;
//# sourceMappingURL=cloudflare.js.map

@@ -1,129 +0,9 @@

import { Inngest } from "./components/Inngest";
import { InngestFunction } from "./components/InngestFunction";
import type { FunctionConfig, RegisterOptions, RegisterRequest, StepRunResponse } from "./types";
import { ServeHandler } from "./components/InngestCommHandler";
/**
* A handler for serving Inngest functions. This type should be used
* whenever a handler for a new framework is being added to enforce that the
* registration process is always the same for the user.
*
* @public
*/
export declare type ServeHandler = (
/**
* The name of this app, used to scope and group Inngest functions, or
* the `Inngest` instance used to declare all functions.
*/
nameOrInngest: string | Inngest<any>,
/**
* An array of the functions to serve and register with Inngest.
*/
functions: InngestFunction<any>[],
/**
* A set of options to further configure the registration of Inngest
* functions.
*/
opts?: RegisterOptions) => any;
/**
* Serve and register any declared functions with Inngest, making them available
* to be triggered by events.
*
* Can either take an `Inngest` instance and a signing key, or can be used to
* create custom handlers by passing in an `InngestCommHandler`.
*
* @public
*/
export declare const serve: (...args: Parameters<ServeHandler> | [commHandler: InngestCommHandler]) => any;
/**
* TODO Instead of `createHandler`, expose `createRequest` and `handleResponse`
*
* Overriding `createHandler` requires that we always remember crucial steps,
* e.g. validating signatures, handling POST, etc.
*
* We should instead require that new comm handlers override only two functions:
*
* `createRequest()`
* This is the function that is exposed. It must return a valid `HandlerRequest`
*
* `handleResponse()`
* The input is a `StepResponse`, and output can be anything needed for the
* platform
*
* This needs to also account for the ability to validate signatures etc.
*
* @public
*/
export declare class InngestCommHandler {
name: string;
/**
* The URL of the Inngest function registration endpoint.
*/
private readonly inngestRegisterUrl;
protected readonly frameworkName: string;
protected signingKey: string | undefined;
/**
* A property that can be set to indicate whether or not we believe we are in
* production mode.
*
* Should be set every time a request is received.
*/
protected _isProd: boolean;
private readonly headers;
private readonly fetch;
/**
* Whether we should show the SDK Landing Page.
*
* This purposefully does not take in to account any environment variables, as
* accessing them safely is platform-specific.
*/
protected readonly showLandingPage: boolean | undefined;
protected readonly serveHost: string | undefined;
protected readonly servePath: string | undefined;
/**
* A private collection of functions that are being served. This map is used
* to find and register functions when interacting with Inngest Cloud.
*/
private readonly fns;
constructor(nameOrInngest: string | Inngest<any>, functions: InngestFunction<any>[], { inngestRegisterUrl, fetch, landingPage, signingKey, serveHost, servePath, }?: RegisterOptions);
private get hashedSigningKey();
createHandler(): any;
protected runStep(functionId: string, stepId: string, data: any): Promise<StepRunResponse>;
protected configs(url: URL): FunctionConfig[];
/**
* Returns an SDK header split in to three parts so that they can be used for
* different purposes.
*
* To use the entire string, run `this.sdkHeader.join("")`.
*/
protected get sdkHeader(): [
prefix: string,
version: RegisterRequest["sdk"],
suffix: string
];
/**
* Return an Inngest serve endpoint URL given a potential `path` and `host`.
*
* Will automatically use the `serveHost` and `servePath` if they have been
* set when registering.
*/
protected reqUrl(
/**
* The path of the Inngest register URL to create. Regardless of the value,
* will be overwritten by `servePath` if it has been set.
*/
path?: string,
/**
* The host of the Inngest register URL to create. Regardless of the value,
* will be overwritten by `serveHost` if it has been set.
*/
host?: string): URL;
protected registerBody(url: URL): RegisterRequest;
protected register(url: URL, devServerHost: string | undefined): Promise<{
status: number;
message: string;
}>;
private get isProd();
protected shouldShowLandingPage(strEnvVar: string | undefined): boolean;
protected validateSignature(): boolean;
protected signResponse(): string;
}
export declare const serve: ServeHandler;
//# sourceMappingURL=express.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InngestCommHandler = exports.serve = void 0;
const hash_js_1 = require("hash.js");
const zod_1 = require("zod");
exports.serve = void 0;
const InngestCommHandler_1 = require("./components/InngestCommHandler");
const consts_1 = require("./helpers/consts");
const devserver_1 = require("./helpers/devserver");
const scalar_1 = require("./helpers/scalar");
const landing_1 = require("./landing");
const version_1 = require("./version");
/**
* A schema for the response from Inngest when registering.
*/
const registerResSchema = zod_1.z.object({
status: zod_1.z.number().default(200),
skipped: zod_1.z.boolean().optional().default(false),
error: zod_1.z.string().default("Successfully registered"),
});
/**
* Serve and register any declared functions with Inngest, making them available
* to be triggered by events.
*
* Can either take an `Inngest` instance and a signing key, or can be used to
* create custom handlers by passing in an `InngestCommHandler`.
*
* @public
*/
const serve = (...args) => {
if (args.length === 1) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return args[0].createHandler();
}
const [nameOrInngest, fns, opts] = args;
const handler = new InngestCommHandler(nameOrInngest, fns, opts);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return handler.createHandler();
};
exports.serve = serve;
/**
* TODO Instead of `createHandler`, expose `createRequest` and `handleResponse`
*
* Overriding `createHandler` requires that we always remember crucial steps,
* e.g. validating signatures, handling POST, etc.
*
* We should instead require that new comm handlers override only two functions:
*
* `createRequest()`
* This is the function that is exposed. It must return a valid `HandlerRequest`
*
* `handleResponse()`
* The input is a `StepResponse`, and output can be anything needed for the
* platform
*
* This needs to also account for the ability to validate signatures etc.
*
* @public
*/
class InngestCommHandler {
constructor(nameOrInngest, functions, { inngestRegisterUrl, fetch, landingPage, signingKey, serveHost, servePath, } = {}) {
this.frameworkName = "express";
/**
* A property that can be set to indicate whether or not we believe we are in
* production mode.
*
* Should be set every time a request is received.
*/
this._isProd = false;
/**
* A private collection of functions that are being served. This map is used
* to find and register functions when interacting with Inngest Cloud.
*/
this.fns = {};
this.name =
typeof nameOrInngest === "string" ? nameOrInngest : nameOrInngest.name;
this.fns = functions.reduce((acc, fn) => {
const id = fn.id(this.name);
if (acc[id]) {
throw new Error(`Duplicate function ID "${id}"; please change a function's name or provide an explicit ID to avoid conflicts.`);
}
return Object.assign(Object.assign({}, acc), { [id]: fn });
}, {});
this.inngestRegisterUrl = new URL(inngestRegisterUrl || "https://api.inngest.com/fn/register");
this.signingKey = signingKey;
this.showLandingPage = landingPage;
this.serveHost = serveHost;
this.servePath = servePath;
this.headers = {
"Content-Type": "application/json",
"User-Agent": `inngest-js:v${version_1.version} (${this.frameworkName})`,
};
// eslint-disable-next-line @typescript-eslint/no-var-requires
this.fetch = fetch || require("cross-fetch");
}
// hashedSigningKey creates a sha256 checksum of the signing key with the
// same signing key prefix.
get hashedSigningKey() {
var _a;
if (!this.signingKey) {
return "";
}
const prefix = ((_a = this.signingKey.match(/^signkey-(test|prod)-/)) === null || _a === void 0 ? void 0 : _a.shift()) || "";
const key = this.signingKey.replace(/^signkey-(test|prod)-/, "");
// Decode the key from its hex representation into a bytestream
return `${prefix}${(0, hash_js_1.sha256)().update(key, "hex").digest("hex")}`;
}
createHandler() {
return async (req, res) => {
res.setHeader("x-inngest-sdk", this.sdkHeader.join(""));
const hostname = req.get("host") || req.headers["host"];
const protocol = (hostname === null || hostname === void 0 ? void 0 : hostname.includes("://")) ? "" : `${req.protocol}://`;
let reqUrl;
try {
reqUrl = this.reqUrl(req.originalUrl, `${protocol}${hostname || ""}`);
reqUrl.searchParams.delete(consts_1.queryKeys.Introspect);
}
catch (e) {
const message = "Unable to determine your site URL to serve the Inngest handler.";
console.error(message);
return res.status(500).json({ message });
}
if (!this.signingKey && process.env[consts_1.envKeys.SigningKey]) {
this.signingKey = process.env[consts_1.envKeys.SigningKey];
}
this._isProd = process.env.ENVIRONMENT === "production" || process.env.NODE_ENV === "production";
switch (req.method) {
case "GET": {
const showLandingPage = this.shouldShowLandingPage(process.env[consts_1.envKeys.LandingPage]);
if (this._isProd || !showLandingPage)
break;
if (Object.hasOwnProperty.call(req.query, consts_1.queryKeys.Introspect)) {
const introspection = Object.assign(Object.assign({}, this.registerBody(reqUrl)), { devServerURL: (0, devserver_1.devServerUrl)(process.env[consts_1.envKeys.DevServerUrl])
.href, hasSigningKey: Boolean(this.signingKey) });
return void res.status(200).json(introspection);
}
// Grab landing page and serve
res.header("content-type", "text/html; charset=utf-8");
return void res.status(200).send(landing_1.landing);
const serve = (nameOrInngest, fns, opts) => {
const handler = new InngestCommHandler_1.InngestCommHandler("express", nameOrInngest, fns, opts, (req, _res) => {
const hostname = req.get("host") || req.headers["host"];
const protocol = (hostname === null || hostname === void 0 ? void 0 : hostname.includes("://")) ? "" : `${req.protocol}://`;
const url = new URL(req.originalUrl, `${protocol}${hostname || ""}`);
const isProduction = process.env.ENVIRONMENT === "production" ||
process.env.NODE_ENV === "production";
return {
run: () => {
if (req.method === "POST") {
return {
fnId: req.query[consts_1.queryKeys.FnId],
data: req.body,
env: process.env,
isProduction,
url,
};
}
case "PUT": {
// Push config to Inngest.
const { status, message } = await this.register(reqUrl, process.env[consts_1.envKeys.DevServerUrl]);
return void res.status(status).json({ message });
},
register: () => {
if (req.method === "PUT") {
return {
env: process.env,
url,
isProduction,
};
}
case "POST": {
// Inngest is trying to run a step; confirm signed and run.
const { fnId, stepId } = zod_1.z
.object({
fnId: zod_1.z.string().min(1),
stepId: zod_1.z.string().min(1),
})
.parse({
fnId: req.query[consts_1.queryKeys.FnId],
stepId: req.query[consts_1.queryKeys.StepId],
});
const stepRes = await this.runStep(fnId, stepId, req.body);
if (stepRes.status === 500) {
return void res.status(stepRes.status).json(stepRes.error);
}
return void res.status(stepRes.status).json(stepRes.body);
},
view: () => {
if (req.method === "GET") {
return {
env: process.env,
url,
isIntrospection: Object.hasOwnProperty.call(req.query, consts_1.queryKeys.Introspect),
isProduction,
};
}
}
return void res.sendStatus(405);
},
};
}
async runStep(functionId, stepId, data) {
try {
const fn = this.fns[functionId];
if (!fn) {
throw new Error(`Could not find function with ID "${functionId}"`);
}
const { event, steps } = zod_1.z
.object({
event: zod_1.z.object({}).passthrough(),
steps: zod_1.z.object({}).passthrough().optional().nullable(),
})
.parse(data);
const ret = await fn["runFn"]({ event }, steps || {});
const isOp = ret[0];
if (isOp) {
return {
status: 206,
body: ret[1],
};
}
return {
status: 200,
body: ret[1],
};
}, (actionRes, _req, res) => {
for (const [name, value] of Object.entries(actionRes.headers)) {
res.setHeader(name, value);
}
catch (err) {
if (err instanceof Error) {
return {
status: 500,
error: err.stack || err.message,
};
}
return {
status: 500,
error: `Unknown error: ${JSON.stringify(err)}`,
};
}
}
configs(url) {
return Object.values(this.fns).map((fn) => fn["getConfig"](url, this.name));
}
/**
* Returns an SDK header split in to three parts so that they can be used for
* different purposes.
*
* To use the entire string, run `this.sdkHeader.join("")`.
*/
get sdkHeader() {
return ["inngest-", `js:v${version_1.version}`, ` (${this.frameworkName})`];
}
/**
* Return an Inngest serve endpoint URL given a potential `path` and `host`.
*
* Will automatically use the `serveHost` and `servePath` if they have been
* set when registering.
*/
reqUrl(
/**
* The path of the Inngest register URL to create. Regardless of the value,
* will be overwritten by `servePath` if it has been set.
*/
path,
/**
* The host of the Inngest register URL to create. Regardless of the value,
* will be overwritten by `serveHost` if it has been set.
*/
host) {
return new URL(this.servePath || (path === null || path === void 0 ? void 0 : path.trim()) || "", this.serveHost || (host === null || host === void 0 ? void 0 : host.trim()) || "");
}
registerBody(url) {
const body = {
url: url.href,
deployType: "ping",
framework: this.frameworkName,
appName: this.name,
functions: this.configs(url),
sdk: this.sdkHeader[1],
v: "0.1",
};
// Calculate the checksum of the body... without the checksum itself being included.
body.hash = (0, hash_js_1.sha256)().update(JSON.stringify(body)).digest("hex");
return body;
}
async register(url, devServerHost) {
const body = this.registerBody(url);
let res;
// Whenever we register, we check to see if the dev server is up. This
// is a noop and returns false in production.
let registerURL = this.inngestRegisterUrl;
if (!this.isProd) {
const hasDevServer = await (0, devserver_1.devServerAvailable)(devServerHost, this.fetch);
if (hasDevServer) {
registerURL = (0, devserver_1.devServerUrl)(devServerHost, "/fn/register");
}
}
try {
res = await this.fetch(registerURL.href, {
method: "POST",
body: JSON.stringify(body),
headers: Object.assign(Object.assign({}, this.headers), { Authorization: `Bearer ${this.hashedSigningKey}` }),
redirect: "follow",
});
}
catch (err) {
console.error(err);
return {
status: 500,
message: `Failed to register${err instanceof Error ? `; ${err.message}` : ""}`,
};
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
let data = {};
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
data = await res.json();
}
catch (err) {
console.warn("Couldn't unpack register response:", err);
}
const { status, error, skipped } = registerResSchema.parse(data);
// The dev server polls this endpoint to register functions every few
// seconds, but we only want to log that we've registered functions if
// the function definitions change. Therefore, we compare the body sent
// during registration with the body of the current functions and refuse
// to register if the functions are the same.
if (!skipped) {
console.log("registered inngest functions:", res.status, res.statusText, data);
}
return { status, message: error };
}
get isProd() {
return this._isProd;
}
shouldShowLandingPage(strEnvVar) {
var _a, _b;
return (_b = (_a = this.showLandingPage) !== null && _a !== void 0 ? _a : (0, scalar_1.strBoolean)(strEnvVar)) !== null && _b !== void 0 ? _b : true;
}
validateSignature() {
return true;
}
signResponse() {
return "";
}
}
exports.InngestCommHandler = InngestCommHandler;
return res.status(actionRes.status).send(actionRes.body);
});
return handler.createHandler();
};
exports.serve = serve;
//# sourceMappingURL=express.js.map

@@ -13,2 +13,6 @@ import { EventPayload } from "../types";

/**
* Returns the given generic as either itself or a promise of itself.
*/
export declare type MaybePromise<T> = T | Promise<T>;
/**
* Acts like `Partial<T>` but only for the keys in `K`, leaving the rest alone.

@@ -15,0 +19,0 @@ */

export { Inngest } from "./components/Inngest";
export { InngestCommHandler } from "./components/InngestCommHandler";
export type { ServeHandler } from "./components/InngestCommHandler";
export { createFunction, createScheduledFunction, createStepFunction, } from "./helpers/func";
export type { ClientOptions, EventPayload, FunctionOptions, MultiStepFn, MultiStepFnArgs, RegisterOptions, SingleStepFn, SingleStepFnArgs, TimeStr, } from "./types";
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createStepFunction = exports.createScheduledFunction = exports.createFunction = exports.Inngest = void 0;
exports.createStepFunction = exports.createScheduledFunction = exports.createFunction = exports.InngestCommHandler = exports.Inngest = void 0;
var Inngest_1 = require("./components/Inngest");
Object.defineProperty(exports, "Inngest", { enumerable: true, get: function () { return Inngest_1.Inngest; } });
var InngestCommHandler_1 = require("./components/InngestCommHandler");
Object.defineProperty(exports, "InngestCommHandler", { enumerable: true, get: function () { return InngestCommHandler_1.InngestCommHandler; } });
var func_1 = require("./helpers/func");

@@ -7,0 +9,0 @@ Object.defineProperty(exports, "createFunction", { enumerable: true, get: function () { return func_1.createFunction; } });

@@ -1,2 +0,2 @@

import { ServeHandler } from "./express";
import { ServeHandler } from "./components/InngestCommHandler";
/**

@@ -3,0 +3,0 @@ * In Next.js, serve and register any declared functions with Inngest, making

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serve = void 0;
const zod_1 = require("zod");
const express_1 = require("./express");
const InngestCommHandler_1 = require("./components/InngestCommHandler");
const consts_1 = require("./helpers/consts");
const devserver_1 = require("./helpers/devserver");
const env_1 = require("./helpers/env");
const landing_1 = require("./landing");
class NextCommHandler extends express_1.InngestCommHandler {
constructor() {
super(...arguments);
this.frameworkName = "nextjs";
}
createHandler() {
return async (req, res) => {
let reqUrl;
try {
const scheme = process.env.NODE_ENV === "development" ? "http" : "https";
reqUrl = this.reqUrl(req.url, `${scheme}://${req.headers.host || ""}`);
reqUrl.searchParams.delete(consts_1.queryKeys.Introspect);
}
catch (err) {
return void res.status(500).json(err);
}
res.setHeader("x-inngest-sdk", this.sdkHeader.join(""));
if (!this.signingKey && process.env[consts_1.envKeys.SigningKey]) {
this.signingKey = process.env[consts_1.envKeys.SigningKey];
}
this._isProd =
process.env.VERCEL_ENV === "production" ||
process.env.CONTEXT === "production" ||
process.env.ENVIRONMENT === "production";
switch (req.method) {
case "GET": {
const showLandingPage = this.shouldShowLandingPage(process.env[consts_1.envKeys.LandingPage]);
if (this._isProd || !showLandingPage)
break;
if (Object.hasOwnProperty.call(req.query, consts_1.queryKeys.Introspect)) {
const introspection = Object.assign(Object.assign({}, this.registerBody(reqUrl)), { devServerURL: (0, devserver_1.devServerUrl)((0, env_1.devServerHost)()).href, hasSigningKey: Boolean(this.signingKey) });
return void res.status(200).json(introspection);
}
// Grab landing page and serve
res.setHeader("content-type", "text/html; charset=utf-8");
return void res.status(200).send(landing_1.landing);
}
case "PUT": {
// Push config to Inngest.
const { status, message } = await this.register(reqUrl, process.env[consts_1.envKeys.DevServerUrl]);
return void res.status(status).json({ message });
}
case "POST": {
// Inngest is trying to run a step; confirm signed and run.
const { fnId, stepId } = zod_1.z
.object({
fnId: zod_1.z.string().min(1),
stepId: zod_1.z.string().min(1),
})
.parse({
fnId: req.query[consts_1.queryKeys.FnId],
stepId: req.query[consts_1.queryKeys.StepId],
});
const stepRes = await this.runStep(fnId, stepId, req.body);
if (stepRes.status === 500) {
return void res.status(stepRes.status).json(stepRes.error);
}
return void res.status(stepRes.status).json(stepRes.body);
}
}
return void res.status(405).end();
};
}
}
/**

@@ -81,5 +13,49 @@ * In Next.js, serve and register any declared functions with Inngest, making

const serve = (nameOrInngest, fns, opts) => {
return (0, express_1.serve)(new NextCommHandler(nameOrInngest, fns, opts));
const handler = new InngestCommHandler_1.InngestCommHandler("nextjs", nameOrInngest, fns, opts, (req, _res) => {
const scheme = process.env.NODE_ENV === "development" ? "http" : "https";
const url = new URL(req.url, `${scheme}://${req.headers.host || ""}`);
const isProduction = process.env.VERCEL_ENV === "production" ||
process.env.CONTEXT === "production" ||
process.env.ENVIRONMENT === "production";
return {
register: () => {
if (req.method === "PUT") {
return {
env: process.env,
url,
isProduction,
};
}
},
run: () => {
if (req.method === "POST") {
return {
data: req.body,
fnId: req.query[consts_1.queryKeys.FnId],
env: process.env,
isProduction,
url,
};
}
},
view: () => {
if (req.method === "GET") {
return {
env: process.env,
isIntrospection: Object.hasOwnProperty.call(req.query, consts_1.queryKeys.Introspect),
url,
isProduction,
};
}
},
};
}, (actionRes, req, res) => {
for (const [key, value] of Object.entries(actionRes.headers)) {
res.setHeader(key, value);
}
res.status(actionRes.status).send(actionRes.body);
});
return handler.createHandler();
};
exports.serve = serve;
//# sourceMappingURL=next.js.map
{
"name": "inngest",
"version": "0.8.5",
"version": "0.8.6-beta.1",
"description": "Official SDK for Inngest.com",

@@ -5,0 +5,0 @@ "main": "./index.js",

@@ -1,2 +0,2 @@

import { ServeHandler } from "./express";
import { ServeHandler } from "./components/InngestCommHandler";
export interface RedwoodResponse {

@@ -3,0 +3,0 @@ statusCode: number;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serve = void 0;
const zod_1 = require("zod");
const express_1 = require("./express");
const InngestCommHandler_1 = require("./components/InngestCommHandler");
const consts_1 = require("./helpers/consts");
const devserver_1 = require("./helpers/devserver");
const env_1 = require("./helpers/env");
const landing_1 = require("./landing");
class RedwoodCommHandler extends express_1.InngestCommHandler {
constructor() {
super(...arguments);
this.frameworkName = "redwoodjs";
}
createHandler() {
return async (event, context) => {
var _a, _b;
const headers = { "x-inngest-sdk": this.sdkHeader.join("") };
let reqUrl;
try {
const scheme = process.env.NODE_ENV === "development" ? "http" : "https";
reqUrl = this.reqUrl(event.path, `${scheme}://${event.headers.host || ""}`);
reqUrl.searchParams.delete(consts_1.queryKeys.Introspect);
}
catch (err) {
return {
statusCode: 500,
body: JSON.stringify(err),
headers,
};
}
if (!this.signingKey && process.env[consts_1.envKeys.SigningKey]) {
this.signingKey = process.env[consts_1.envKeys.SigningKey];
}
this._isProd =
process.env.VERCEL_ENV === "production" ||
process.env.CONTEXT === "production" ||
process.env.ENVIRONMENT === "production";
switch (event.httpMethod) {
case "GET": {
const showLandingPage = this.shouldShowLandingPage(process.env[consts_1.envKeys.LandingPage]);
if (this._isProd || !showLandingPage)
break;
if (Object.hasOwnProperty.call(event.queryStringParameters, consts_1.queryKeys.Introspect)) {
const introspection = Object.assign(Object.assign({}, this.registerBody(reqUrl)), { devServerURL: (0, devserver_1.devServerUrl)((0, env_1.devServerHost)()).href, hasSigningKey: Boolean(this.signingKey) });
return {
statusCode: 200,
body: JSON.stringify(introspection),
headers,
};
}
// Grab landing page and serve
/**
* In Redwood.js, serve and register any declared functions with Inngest, making
* them available to be triggered by events.
*
* @public
*/
const serve = (nameOrInngest, fns, opts) => {
const handler = new InngestCommHandler_1.InngestCommHandler("redwoodjs", nameOrInngest, fns, opts, (event, _context) => {
const scheme = process.env.NODE_ENV === "development" ? "http" : "https";
const url = new URL(event.path, `${scheme}://${event.headers.host || ""}`);
const isProduction = process.env.VERCEL_ENV === "production" ||
process.env.CONTEXT === "production" ||
process.env.ENVIRONMENT === "production";
return {
register: () => {
if (event.httpMethod === "PUT") {
return {
statusCode: 200,
body: landing_1.landing,
headers: Object.assign(Object.assign({}, headers), { "content-type": "text/html; charset=utf-8" }),
env: process.env,
isProduction,
url,
};
}
case "PUT": {
// Push config to Inngest.
const { status, message } = await this.register(reqUrl, process.env[consts_1.envKeys.DevServerUrl]);
return {
statusCode: status,
body: JSON.stringify({ message }),
headers,
};
}
case "POST": {
// Inngest is trying to run a step; confirm signed and run.
const { fnId, stepId } = zod_1.z
.object({
fnId: zod_1.z.string().min(1),
stepId: zod_1.z.string().min(1),
})
.parse({
fnId: (_a = event.queryStringParameters) === null || _a === void 0 ? void 0 : _a[consts_1.queryKeys.FnId],
stepId: (_b = event.queryStringParameters) === null || _b === void 0 ? void 0 : _b[consts_1.queryKeys.StepId],
});
},
run: () => {
var _a;
if (event.httpMethod === "POST") {
/**

@@ -83,39 +36,37 @@ * Some requests can be base64 encoded, requiring us to decode it

*/
const strJson = event.body
const data = JSON.parse(event.body
? event.isBase64Encoded
? Buffer.from(event.body, "base64").toString()
: event.body
: "{}";
const stepRes = await this.runStep(fnId, stepId, JSON.parse(strJson));
if (stepRes.status === 500) {
return {
statusCode: stepRes.status,
body: JSON.stringify(stepRes.error),
headers,
};
}
: "{}");
return {
statusCode: stepRes.status,
body: JSON.stringify(stepRes.body),
headers,
env: process.env,
isProduction,
url,
data,
fnId: (_a = event.queryStringParameters) === null || _a === void 0 ? void 0 : _a[consts_1.queryKeys.FnId],
};
}
}
return {
statusCode: 405,
headers,
};
},
view: () => {
if (event.httpMethod === "GET") {
return {
env: process.env,
isProduction,
url,
isIntrospection: Object.hasOwnProperty.call(event.queryStringParameters, consts_1.queryKeys.Introspect),
};
}
},
};
}
}
/**
* In Redwood.js, serve and register any declared functions with Inngest, making
* them available to be triggered by events.
*
* @public
*/
const serve = (nameOrInngest, fns, opts) => {
return (0, express_1.serve)(new RedwoodCommHandler(nameOrInngest, fns, opts));
}, (actionRes) => {
return {
statusCode: actionRes.status,
body: actionRes.body,
headers: actionRes.headers,
};
});
return handler.createHandler();
};
exports.serve = serve;
//# sourceMappingURL=redwood.js.map

@@ -1,2 +0,2 @@

import { ServeHandler } from "./express";
import { ServeHandler } from "./components/InngestCommHandler";
/**

@@ -3,0 +3,0 @@ * In Remix, serve and register any declared functions with Inngest, making them

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serve = void 0;
const zod_1 = require("zod");
const express_1 = require("./express");
const InngestCommHandler_1 = require("./components/InngestCommHandler");
const consts_1 = require("./helpers/consts");
const devserver_1 = require("./helpers/devserver");
const env_1 = require("./helpers/env");
const landing_1 = require("./landing");
/**
* app/inngest/index.server.ts
* app/routes/api/inngest.ts
*/
class RemixCommHandler extends express_1.InngestCommHandler {
constructor() {
super(...arguments);
this.frameworkName = "remix";
}
createHandler() {
return async ({ request: req, }) => {
/**
* If `Response` isn't included in this environment, it's probably a Node
* env that isn't already polyfilling. In this case, we can polyfill it
* here to be safe.
*/
let Res;
if (typeof Response === "undefined") {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-var-requires
Res = require("cross-fetch").Response;
}
else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Res = Response;
}
const headers = { "x-inngest-sdk": this.sdkHeader.join("") };
let reqUrl;
let isIntrospection;
try {
reqUrl = this.reqUrl(req.url, `https://${req.headers.get("host") || ""}`);
isIntrospection = reqUrl.searchParams.has(consts_1.queryKeys.Introspect);
reqUrl.searchParams.delete(consts_1.queryKeys.Introspect);
}
catch (err) {
return new Res(JSON.stringify(err), {
status: 500,
headers,
});
}
if (!this.signingKey && process.env[consts_1.envKeys.SigningKey]) {
this.signingKey = process.env[consts_1.envKeys.SigningKey];
}
this._isProd =
process.env.VERCEL_ENV === "production" ||
process.env.CONTEXT === "production" ||
process.env.ENVIRONMENT === "production";
switch (req.method) {
case "GET": {
const showLandingPage = this.shouldShowLandingPage(process.env[consts_1.envKeys.LandingPage]);
if (this._isProd || !showLandingPage)
break;
if (isIntrospection) {
const introspection = Object.assign(Object.assign({}, this.registerBody(reqUrl)), { devServerURL: (0, devserver_1.devServerUrl)((0, env_1.devServerHost)()).href, hasSigningKey: Boolean(this.signingKey) });
return new Res(JSON.stringify(introspection), {
status: 200,
headers,
});
}
// Grab landing page and serve
return new Res(landing_1.landing, {
status: 200,
headers: Object.assign(Object.assign({}, headers), { "content-type": "text/html; charset=utf-8" }),
});
}
case "PUT": {
// Push config to Inngest.
const { status, message } = await this.register(reqUrl, process.env[consts_1.envKeys.DevServerUrl]);
return new Res(JSON.stringify({ message }), {
status,
headers,
});
}
case "POST": {
// Inngest is trying to run a step; confirm signed and run.
const { fnId, stepId } = zod_1.z
.object({
fnId: zod_1.z.string().min(1),
stepId: zod_1.z.string().min(1),
})
.parse({
fnId: reqUrl.searchParams.get(consts_1.queryKeys.FnId),
stepId: reqUrl.searchParams.get(consts_1.queryKeys.StepId),
});
const stepRes = await this.runStep(fnId, stepId, await req.json());
if (stepRes.status === 500) {
return new Res(JSON.stringify(stepRes.error), {
status: stepRes.status,
headers,
});
}
return new Res(JSON.stringify(stepRes.body), {
status: stepRes.status,
headers,
});
}
}
return new Res(null, { status: 405, headers });
};
}
}
/**
* In Remix, serve and register any declared functions with Inngest, making them

@@ -133,5 +29,64 @@ * available to be triggered by events.

const serve = (nameOrInngest, fns, opts) => {
return (0, express_1.serve)(new RemixCommHandler(nameOrInngest, fns, opts));
// return defaultServe(new RemixCommHandler(nameOrInngest, fns, opts));
const handler = new InngestCommHandler_1.InngestCommHandler("remix", nameOrInngest, fns, opts, ({ request: req }) => {
const url = new URL(req.url, `https://${req.headers.get("host") || ""}`);
const isProduction = process.env.VERCEL_ENV === "production" ||
process.env.CONTEXT === "production" ||
process.env.ENVIRONMENT === "production";
const env = process.env;
return {
register: () => {
if (req.method === "PUT") {
return {
env,
isProduction,
url,
};
}
},
run: async () => {
if (req.method === "POST") {
return {
data: (await req.json()),
env,
fnId: url.searchParams.get(consts_1.queryKeys.FnId),
isProduction,
url,
};
}
},
view: () => {
if (req.method === "GET") {
return {
env,
isIntrospection: url.searchParams.has(consts_1.queryKeys.Introspect),
isProduction,
url,
};
}
},
};
}, ({ body, status, headers }) => {
/**
* If `Response` isn't included in this environment, it's probably a Node
* env that isn't already polyfilling. In this case, we can polyfill it
* here to be safe.
*/
let Res;
if (typeof Response === "undefined") {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-var-requires
Res = require("cross-fetch").Response;
}
else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Res = Response;
}
return new Res(body, {
status,
headers,
});
});
return handler.createHandler();
};
exports.serve = serve;
//# sourceMappingURL=remix.js.map

@@ -1,2 +0,2 @@

export declare const version = "0.8.5";
export declare const version = "0.8.6-beta.1";
//# sourceMappingURL=version.d.ts.map

@@ -5,3 +5,3 @@ "use strict";

// Generated by genversion.
exports.version = "0.8.5";
exports.version = "0.8.6-beta.1";
//# sourceMappingURL=version.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc