Comparing version 1.7.0 to 1.7.1-streaming.1
# inngest | ||
## 1.7.1 | ||
### Patch Changes | ||
- 34b6d39: INN-1240 Add `queueMicrotask()` fallback for restrictive environments | ||
## 1.7.0 | ||
@@ -4,0 +10,0 @@ |
@@ -77,7 +77,2 @@ import type { PartialK, SendEventPayload, SingleOrArray } from "../helpers/types"; | ||
/** | ||
* Given a potential fetch function, return the fetch function to use based on | ||
* this and the environment. | ||
*/ | ||
private static parseFetch; | ||
/** | ||
* Set the event key for this instance of Inngest. This is useful if for some | ||
@@ -84,0 +79,0 @@ * reason the key is not available at time of instantiation or present in the |
@@ -87,19 +87,5 @@ "use strict"; | ||
}); | ||
this.fetch = Inngest.parseFetch(fetch); | ||
this.fetch = (0, env_1.getFetch)(fetch); | ||
} | ||
/** | ||
* Given a potential fetch function, return the fetch function to use based on | ||
* this and the environment. | ||
*/ | ||
static parseFetch(fetchArg) { | ||
if (fetchArg) { | ||
return fetchArg; | ||
} | ||
if (typeof fetch !== "undefined") { | ||
return fetch; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
return require("cross-fetch"); | ||
} | ||
/** | ||
* Set the event key for this instance of Inngest. This is useful if for some | ||
@@ -106,0 +92,0 @@ * reason the key is not available at time of instantiation or present in the |
import { ServerTiming } from "../helpers/ServerTiming"; | ||
import type { MaybePromise } from "../helpers/types"; | ||
import { FunctionConfig, LogLevel, RegisterOptions, RegisterRequest, StepRunResponse } from "../types"; | ||
import type { Inngest } from "./Inngest"; | ||
import { Inngest } from "./Inngest"; | ||
import type { InngestFunction } from "./InngestFunction"; | ||
@@ -94,3 +94,3 @@ /** | ||
*/ | ||
export declare class InngestCommHandler<H extends Handler, TransformedRes> { | ||
export declare class InngestCommHandler<H extends Handler, TResTransform extends (res: ActionResponse<string>, ...args: Parameters<H>) => any, TStreamTransform extends (res: ActionResponse<ReadableStream>, ...args: Parameters<H>) => any> { | ||
/** | ||
@@ -109,3 +109,4 @@ * The name of this serve handler, e.g. `"My App"`. It's recommended that this | ||
*/ | ||
readonly transformRes: (res: ActionResponse, ...args: Parameters<H>) => TransformedRes; | ||
readonly transformRes: TResTransform; | ||
readonly streamTransformRes: TStreamTransform | undefined; | ||
/** | ||
@@ -181,2 +182,3 @@ * The URL of the Inngest function registration endpoint. | ||
protected readonly logLevel: LogLevel; | ||
protected readonly allowEdgeStreaming: boolean; | ||
/** | ||
@@ -216,3 +218,3 @@ * A private collection of just Inngest functions, as they have been passed | ||
*/ | ||
functions: InngestFunction<any, any, any>[], { inngestRegisterUrl, fetch, landingPage, logLevel, signingKey, serveHost, servePath, }: RegisterOptions | undefined, | ||
functions: InngestFunction<any, any, any>[], { inngestRegisterUrl, fetch, landingPage, logLevel, signingKey, serveHost, servePath, allowEdgeStreaming, }: RegisterOptions | undefined, | ||
/** | ||
@@ -267,3 +269,28 @@ * The `handler` is the function your framework requires to handle a | ||
*/ | ||
transformRes: (actionRes: ActionResponse, ...args: Parameters<H>) => TransformedRes); | ||
transformRes: TResTransform, | ||
/** | ||
* The `streamTransformRes` function, if defined, declares that this handler | ||
* supports streaming responses back to Inngest. This is useful for | ||
* functions that are expected to take a long time, as edge streaming can | ||
* often circumvent restrictive request timeouts and other limitations. | ||
* | ||
* If your handler does not support streaming, do not define this function. | ||
* | ||
* It receives the output of the Inngest SDK and can decide how to package | ||
* up that information to appropriately return the information in a stream | ||
* to Inngest. | ||
* | ||
* Mostly, this is taking the given parameters and returning a new | ||
* `Response`. | ||
* | ||
* The function is passed an {@link ActionResponse} (an object containing a | ||
* `status` code, a `headers` object, and `body`, a `ReadableStream`), as | ||
* well as every parameter passed to the given `handler` function. This | ||
* ensures you can appropriately handle the response, including use of any | ||
* required parameters such as `res` in Express-/Connect-like frameworks. | ||
* | ||
* This should never be defined by the user; a {@link ServeHandler} should | ||
* abstract this. | ||
*/ | ||
streamTransformRes?: TStreamTransform); | ||
private get hashedSigningKey(); | ||
@@ -293,3 +320,3 @@ /** | ||
*/ | ||
createHandler(): (...args: Parameters<H>) => Promise<TransformedRes>; | ||
createHandler(): (...args: Parameters<H>) => Promise<Awaited<ReturnType<TResTransform>>>; | ||
/** | ||
@@ -355,3 +382,3 @@ * Given a set of functions to check if an action is available from the | ||
*/ | ||
export interface ActionResponse { | ||
export interface ActionResponse<TBody extends string | ReadableStream = string> { | ||
/** | ||
@@ -368,3 +395,3 @@ * The HTTP status code to return. | ||
*/ | ||
body: string; | ||
body: TBody; | ||
} | ||
@@ -371,0 +398,0 @@ /** |
@@ -15,3 +15,5 @@ "use strict"; | ||
const errors_1 = require("../helpers/errors"); | ||
const functions_1 = require("../helpers/functions"); | ||
const scalar_1 = require("../helpers/scalar"); | ||
const stream_1 = require("../helpers/stream"); | ||
const strings_1 = require("../helpers/strings"); | ||
@@ -90,3 +92,3 @@ const landing_1 = require("../landing"); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
functions, { inngestRegisterUrl, fetch, landingPage, logLevel = "info", signingKey, serveHost, servePath, } = {}, | ||
functions, { inngestRegisterUrl, fetch, landingPage, logLevel = "info", signingKey, serveHost, servePath, allowEdgeStreaming, } = {}, | ||
/** | ||
@@ -141,3 +143,28 @@ * The `handler` is the function your framework requires to handle a | ||
*/ | ||
transformRes) { | ||
transformRes, | ||
/** | ||
* The `streamTransformRes` function, if defined, declares that this handler | ||
* supports streaming responses back to Inngest. This is useful for | ||
* functions that are expected to take a long time, as edge streaming can | ||
* often circumvent restrictive request timeouts and other limitations. | ||
* | ||
* If your handler does not support streaming, do not define this function. | ||
* | ||
* It receives the output of the Inngest SDK and can decide how to package | ||
* up that information to appropriately return the information in a stream | ||
* to Inngest. | ||
* | ||
* Mostly, this is taking the given parameters and returning a new | ||
* `Response`. | ||
* | ||
* The function is passed an {@link ActionResponse} (an object containing a | ||
* `status` code, a `headers` object, and `body`, a `ReadableStream`), as | ||
* well as every parameter passed to the given `handler` function. This | ||
* ensures you can appropriately handle the response, including use of any | ||
* required parameters such as `res` in Express-/Connect-like frameworks. | ||
* | ||
* This should never be defined by the user; a {@link ServeHandler} should | ||
* abstract this. | ||
*/ | ||
streamTransformRes) { | ||
var _a; | ||
@@ -163,2 +190,3 @@ /** | ||
this.transformRes = transformRes; | ||
this.streamTransformRes = streamTransformRes; | ||
/** | ||
@@ -194,9 +222,7 @@ * Provide a hidden option to allow expired signatures to be accepted during | ||
this.logLevel = logLevel; | ||
this.fetch = | ||
fetch || | ||
(typeof appNameOrInngest === "string" | ||
? undefined | ||
: appNameOrInngest["fetch"]) || | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require("cross-fetch"); | ||
this.allowEdgeStreaming = allowEdgeStreaming !== null && allowEdgeStreaming !== void 0 ? allowEdgeStreaming : true; | ||
this.fetch = (0, env_1.getFetch)(fetch || | ||
(typeof appNameOrInngest === "string" | ||
? undefined | ||
: appNameOrInngest["fetch"])); | ||
} | ||
@@ -246,5 +272,54 @@ // hashedSigningKey creates a sha256 checksum of the signing key with the | ||
// eslint-disable-next-line @typescript-eslint/await-thenable | ||
const actions = await timer.wrap("handler", () => this.handler(...args)); | ||
const actionRes = await timer.wrap("action", () => this.handleAction(actions, timer)); | ||
return timer.wrap("res", () => this.transformRes(actionRes, ...args)); | ||
const rawActions = await timer.wrap("handler", () => this.handler(...args)); | ||
/** | ||
* For each function within the actions returned, ensure that its value | ||
* caches when run. This ensures that the function is only run once, even | ||
* if it's called multiple times throughout this handler's invocation. | ||
* | ||
* Many frameworks have issues with multiple calls to req/res objects; | ||
* reading a request's body multiple times is a common example. This makes | ||
* sure to handle this without having to pass around references. | ||
*/ | ||
const actions = Object.fromEntries(Object.entries(rawActions).map(([key, val]) => [ | ||
key, | ||
typeof val === "function" ? (0, functions_1.cacheFn)(val) : val, | ||
])); | ||
const getHeaders = () => (Object.assign(Object.assign({}, (0, env_1.inngestHeaders)({ | ||
env: actions.env, | ||
framework: this.frameworkName, | ||
})), { "Server-Timing": timer.getHeader() })); | ||
const actionRes = timer.wrap("action", () => this.handleAction(actions, timer)); | ||
/** | ||
* Prepares an action response by merging returned data to provide | ||
* trailing information such as `Server-Timing` headers. | ||
* | ||
* It should always prioritize the headers returned by the action, as | ||
* they may contain important information such as `Content-Type`. | ||
*/ | ||
const prepareActionRes = (res) => (Object.assign(Object.assign({}, res), { headers: Object.assign(Object.assign({}, getHeaders()), res.headers) })); | ||
if (this.allowEdgeStreaming && | ||
this.streamTransformRes && | ||
(0, env_1.platformSupportsStreaming)(actions.env)) { | ||
const runRes = await actions.run(); | ||
if (runRes) { | ||
const { stream, finalize } = await (0, stream_1.createStream)(); | ||
/** | ||
* Errors are handled by `handleAction` here to ensure that an | ||
* appropriate response is always given. | ||
*/ | ||
void actionRes.then((res) => finalize(prepareActionRes(res))); | ||
return timer.wrap("res", () => { | ||
var _a; | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return (_a = this.streamTransformRes) === null || _a === void 0 ? void 0 : _a.call(this, { | ||
status: 201, | ||
headers: getHeaders(), | ||
body: stream, | ||
}, ...args); | ||
}); | ||
} | ||
} | ||
return timer.wrap("res", async () => actionRes.then((res) => | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
this.transformRes(prepareActionRes(res), ...args))); | ||
}; | ||
@@ -282,3 +357,5 @@ } | ||
(0, errors_1.serializeError)(new Error("Unknown error; function failed but no error was returned"))), | ||
headers: Object.assign(Object.assign({}, getHeaders()), { "Content-Type": "application/json" }), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}; | ||
@@ -289,3 +366,5 @@ } | ||
body: JSON.stringify(stepRes.body), | ||
headers: Object.assign(Object.assign({}, getHeaders()), { "Content-Type": "application/json" }), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}; | ||
@@ -301,3 +380,3 @@ } | ||
body: "", | ||
headers: getHeaders(), | ||
headers: {}, | ||
}; | ||
@@ -310,3 +389,5 @@ } | ||
body: JSON.stringify(introspection), | ||
headers: Object.assign(Object.assign({}, getHeaders()), { "Content-Type": "application/json" }), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}; | ||
@@ -317,3 +398,5 @@ } | ||
body: landing_1.landing, | ||
headers: Object.assign(Object.assign({}, getHeaders()), { "Content-Type": "text/html; charset=utf-8" }), | ||
headers: { | ||
"Content-Type": "text/html; charset=utf-8", | ||
}, | ||
}; | ||
@@ -328,3 +411,5 @@ } | ||
body: JSON.stringify({ message }), | ||
headers: Object.assign(Object.assign({}, getHeaders()), { "Content-Type": "application/json" }), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}; | ||
@@ -337,3 +422,5 @@ } | ||
body: JSON.stringify(Object.assign({ type: "internal" }, (0, errors_1.serializeError)(err))), | ||
headers: Object.assign(Object.assign({}, getHeaders()), { "Content-Type": "application/json" }), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}; | ||
@@ -344,3 +431,3 @@ } | ||
body: "", | ||
headers: getHeaders(), | ||
headers: {}, | ||
}; | ||
@@ -347,0 +434,0 @@ } |
@@ -11,4 +11,4 @@ import type { ServeHandler } from "./components/InngestCommHandler"; | ||
}; | ||
export declare const serve: (name: Parameters<ServeHandler>[0], fns: Parameters<ServeHandler>[1], opts: Parameters<ServeHandler>[2] & Required<Pick<NonNullable<Parameters<ServeHandler>[2]>, "serveHost">>) => (main: Main) => Promise<import("./components/InngestCommHandler").ActionResponse>; | ||
export declare const serve: (name: Parameters<ServeHandler>[0], fns: Parameters<ServeHandler>[1], opts: Parameters<ServeHandler>[2] & Required<Pick<NonNullable<Parameters<ServeHandler>[2]>, "serveHost">>) => (main: Main) => Promise<import("./components/InngestCommHandler").ActionResponse<string>>; | ||
export {}; | ||
//# sourceMappingURL=digitalocean.d.ts.map |
@@ -57,2 +57,15 @@ /** | ||
}) => Record<string, string>; | ||
/** | ||
* Returns `true` if we believe the current environment supports streaming | ||
* responses back to Inngest. | ||
* | ||
* We run a check directly related to the platform we believe we're running on, | ||
* usually based on environment variables. | ||
*/ | ||
export declare const platformSupportsStreaming: (env?: Record<string, string | undefined>) => boolean; | ||
/** | ||
* Given a potential fetch function, return the fetch function to use based on | ||
* this and the environment. | ||
*/ | ||
export declare const getFetch: (givenFetch?: typeof fetch) => typeof fetch; | ||
//# sourceMappingURL=env.d.ts.map |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.inngestHeaders = exports.allProcessEnv = exports.processEnv = exports.getEnvironmentName = exports.isProd = exports.devServerHost = void 0; | ||
exports.getFetch = exports.platformSupportsStreaming = exports.inngestHeaders = exports.allProcessEnv = exports.processEnv = exports.getEnvironmentName = exports.isProd = exports.devServerHost = void 0; | ||
const version_1 = require("../version"); | ||
@@ -142,10 +142,27 @@ const consts_1 = require("./consts"); | ||
exports.inngestHeaders = inngestHeaders; | ||
/** | ||
* A set of checks that, given an environment, will return `true` if the current | ||
* environment is running on the platform with the given name. | ||
*/ | ||
const platformChecks = { | ||
vercel: (env) => env[consts_1.envKeys.IsVercel] === "1", | ||
netlify: (env) => env[consts_1.envKeys.IsNetlify] === "true", | ||
"cloudflare-pages": (env) => env[consts_1.envKeys.IsCloudflarePages] === "1", | ||
render: (env) => env[consts_1.envKeys.IsRender] === "true", | ||
railway: (env) => Boolean(env[consts_1.envKeys.RailwayEnvironment]), | ||
}; | ||
/** | ||
* A set of checks that, given an environment, will return `true` if the current | ||
* environment and platform supports streaming responses back to Inngest. | ||
* | ||
* Streaming capability is both framework and platform-based. Frameworks are | ||
* supported in serve handlers, and platforms are checked here. | ||
* | ||
* As such, this record declares which platforms we explicitly support for | ||
* streaming and is used by {@link platformSupportsStreaming}. | ||
*/ | ||
const streamingChecks = { | ||
vercel: (_env) => typeof EdgeRuntime === "string", | ||
}; | ||
const getPlatformName = (env) => { | ||
const platformChecks = { | ||
vercel: (env) => env[consts_1.envKeys.IsVercel] === "1", | ||
netlify: (env) => env[consts_1.envKeys.IsNetlify] === "true", | ||
"cloudflare-pages": (env) => env[consts_1.envKeys.IsCloudflarePages] === "1", | ||
render: (env) => env[consts_1.envKeys.IsRender] === "true", | ||
railway: (env) => Boolean(env[consts_1.envKeys.RailwayEnvironment]), | ||
}; | ||
return Object.keys(platformChecks).find((key) => { | ||
@@ -155,2 +172,46 @@ return platformChecks[key](env); | ||
}; | ||
/** | ||
* Returns `true` if we believe the current environment supports streaming | ||
* responses back to Inngest. | ||
* | ||
* We run a check directly related to the platform we believe we're running on, | ||
* usually based on environment variables. | ||
*/ | ||
const platformSupportsStreaming = (env = (0, exports.allProcessEnv)()) => { | ||
var _a, _b; | ||
return ((_b = (_a = streamingChecks[getPlatformName(env)]) === null || _a === void 0 ? void 0 : _a.call(streamingChecks, env)) !== null && _b !== void 0 ? _b : false); | ||
}; | ||
exports.platformSupportsStreaming = platformSupportsStreaming; | ||
/** | ||
* Given a potential fetch function, return the fetch function to use based on | ||
* this and the environment. | ||
*/ | ||
const getFetch = (givenFetch) => { | ||
if (givenFetch) { | ||
return givenFetch; | ||
} | ||
/** | ||
* Browser or Node 18+ | ||
*/ | ||
try { | ||
if (typeof globalThis !== "undefined" && "fetch" in globalThis) { | ||
return fetch.bind(globalThis); | ||
} | ||
} | ||
catch (err) { | ||
// no-op | ||
} | ||
/** | ||
* Existing polyfilled fetch | ||
*/ | ||
if (typeof fetch !== "undefined") { | ||
return fetch; | ||
} | ||
/** | ||
* Environments where fetch cannot be found and must be polyfilled | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
return require("cross-fetch"); | ||
}; | ||
exports.getFetch = getFetch; | ||
//# sourceMappingURL=env.js.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveNextTick = exports.resolveAfterPending = exports.createFrozenPromise = void 0; | ||
/** | ||
* Some environments don't allow access to the global queueMicrotask(). While we | ||
* had assumed this was only true for those powered by earlier versions of Node | ||
* (<14) that we don't officially support, Vercel's Edge Functions also obscure | ||
* the function, even though the platform it's based on (Cloudflare Workers) | ||
* appropriately exposes it. | ||
* | ||
* Therefore, we can fall back to a reasonable alternative of | ||
* `Promise.resolve().then(fn)` instead. This will be slightly slower, but at | ||
* least we can still work in these environments. | ||
* | ||
* This package does exactly that, enabling us to use `queueMicrotask()` in all | ||
* modern JS engines. | ||
* | ||
* See {@link https://www.npmjs.com/package/queue-microtask}. | ||
*/ | ||
const queue_microtask_1 = __importDefault(require("queue-microtask")); | ||
/** | ||
* A helper function to create a `Promise` that will never settle. | ||
@@ -37,3 +57,3 @@ * | ||
const iterate = () => { | ||
queueMicrotask(() => { | ||
(0, queue_microtask_1.default)(() => { | ||
if (i++ > 1000) { | ||
@@ -40,0 +60,0 @@ return resolve(); |
@@ -88,3 +88,3 @@ "use strict"; | ||
}; | ||
}, ({ body, status, headers }, _req) => { | ||
}, ({ body, status, headers }) => { | ||
return Promise.resolve({ | ||
@@ -91,0 +91,0 @@ body, |
@@ -1,2 +0,2 @@ | ||
import { ServeHandler } from "./components/InngestCommHandler"; | ||
import type { ServeHandler } from "./components/InngestCommHandler"; | ||
export declare const name = "nextjs"; | ||
@@ -3,0 +3,0 @@ /** |
52
next.js
@@ -15,5 +15,22 @@ "use strict"; | ||
const serve = (nameOrInngest, fns, opts) => { | ||
const handler = new InngestCommHandler_1.InngestCommHandler(exports.name, nameOrInngest, fns, opts, (req, _res) => { | ||
const scheme = (0, env_1.processEnv)("NODE_ENV") === "development" ? "http" : "https"; | ||
const url = new URL(req.url, `${scheme}://${req.headers.host || ""}`); | ||
const optsWithFetch = Object.assign({}, opts); | ||
const handler = new InngestCommHandler_1.InngestCommHandler(exports.name, nameOrInngest, fns, optsWithFetch, (req, _res) => { | ||
const isEdge = ((req) => { var _a; return typeof ((_a = req === null || req === void 0 ? void 0 : req.headers) === null || _a === void 0 ? void 0 : _a.get) === "function"; })(req); | ||
const url = isEdge | ||
? new URL(req.url) | ||
: new URL(req.url, `${(0, env_1.processEnv)("NODE_ENV") === "development" ? "http" : "https"}://${req.headers.host || ""}`); | ||
const getQueryParam = (key) => { | ||
var _a, _b; | ||
return ((_b = (isEdge ? url.searchParams.get(key) : (_a = req.query[key]) === null || _a === void 0 ? void 0 : _a.toString())) !== null && _b !== void 0 ? _b : undefined); | ||
}; | ||
const hasQueryParam = (key) => { | ||
var _a; | ||
return ((_a = (isEdge | ||
? url.searchParams.has(key) | ||
: Object.hasOwnProperty.call(req.query, key))) !== null && _a !== void 0 ? _a : false); | ||
}; | ||
const getHeader = (key) => { | ||
var _a, _b; | ||
return ((_b = (isEdge ? req.headers.get(key) : (_a = req.headers[key]) === null || _a === void 0 ? void 0 : _a.toString())) !== null && _b !== void 0 ? _b : undefined); | ||
}; | ||
return { | ||
@@ -25,13 +42,15 @@ url, | ||
return { | ||
deployId: (_a = req.query[consts_1.queryKeys.DeployId]) === null || _a === void 0 ? void 0 : _a.toString(), | ||
deployId: (_a = getQueryParam(consts_1.queryKeys.DeployId)) === null || _a === void 0 ? void 0 : _a.toString(), | ||
}; | ||
} | ||
}, | ||
run: () => { | ||
run: async () => { | ||
if (req.method === "POST") { | ||
return { | ||
data: req.body, | ||
fnId: req.query[consts_1.queryKeys.FnId], | ||
stepId: req.query[consts_1.queryKeys.StepId], | ||
signature: req.headers[consts_1.headerKeys.Signature], | ||
data: isEdge | ||
? (await req.json()) | ||
: req.body, | ||
fnId: getQueryParam(consts_1.queryKeys.FnId), | ||
stepId: getQueryParam(consts_1.queryKeys.StepId), | ||
signature: getHeader(consts_1.headerKeys.Signature), | ||
}; | ||
@@ -43,3 +62,3 @@ } | ||
return { | ||
isIntrospection: Object.hasOwnProperty.call(req.query, consts_1.queryKeys.Introspect), | ||
isIntrospection: hasQueryParam(consts_1.queryKeys.Introspect), | ||
}; | ||
@@ -49,7 +68,12 @@ } | ||
}; | ||
}, (actionRes, req, res) => { | ||
for (const [key, value] of Object.entries(actionRes.headers)) { | ||
res.setHeader(key, value); | ||
}, ({ body, headers, status }, _req, res) => { | ||
if ("send" in res) { | ||
for (const [key, value] of Object.entries(headers)) { | ||
res.setHeader(key, value); | ||
} | ||
return void res.status(status).send(body); | ||
} | ||
res.status(actionRes.status).send(actionRes.body); | ||
return new Response(body, { status, headers }); | ||
}, ({ body, headers, status }) => { | ||
return new Response(body, { status, headers }); | ||
}); | ||
@@ -56,0 +80,0 @@ return handler.createHandler(); |
{ | ||
"name": "inngest", | ||
"version": "1.7.0", | ||
"version": "1.7.1-streaming.1", | ||
"description": "Official SDK for Inngest.com", | ||
@@ -61,2 +61,3 @@ "main": "./index.js", | ||
"ms": "^2.1.3", | ||
"queue-microtask": "^1.2.3", | ||
"serialize-error-cjs": "^0.1.3", | ||
@@ -99,3 +100,4 @@ "type-fest": "^3.5.1", | ||
"node": "18.12.1", | ||
"yarn": "1.22.19" | ||
"yarn": "1.22.19", | ||
"npm": "9.6.4" | ||
}, | ||
@@ -102,0 +104,0 @@ "peerDependencies": { |
@@ -15,3 +15,7 @@ "use strict"; | ||
const serve = (nameOrInngest, fns, opts) => { | ||
const handler = new InngestCommHandler_1.InngestCommHandler(exports.name, nameOrInngest, fns, opts, (event, _context) => { | ||
const handler = new InngestCommHandler_1.InngestCommHandler(exports.name, nameOrInngest, fns, Object.assign(Object.assign({}, opts), { | ||
/** | ||
* RedwoodJS doesn't support streaming responses. | ||
*/ | ||
allowEdgeStreaming: false }), (event, _context) => { | ||
const scheme = (0, env_1.processEnv)("NODE_ENV") === "development" ? "http" : "https"; | ||
@@ -18,0 +22,0 @@ const url = new URL(event.path, `${scheme}://${event.headers.host || ""}`); |
@@ -416,2 +416,17 @@ import { z } from "zod"; | ||
logLevel?: LogLevel; | ||
/** | ||
* If this is `true`, and streaming is supported by your serve handler (e.g. | ||
* `"inngest/next"`) and your platform (e.g. Vercel), the SDK will attempt to | ||
* stream responses back to Inngest. | ||
* | ||
* This is highly recommended for functions that are expected to take a long | ||
* time, as edge streaming can often circumvent restrictive request timeouts | ||
* and other limitations. | ||
* | ||
* Some serve handlers may override this to `false` if streaming is not | ||
* supported. | ||
* | ||
* Defaults to `true`. | ||
*/ | ||
allowEdgeStreaming?: boolean; | ||
} | ||
@@ -418,0 +433,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
export declare const version = "1.7.0"; | ||
export declare const version = "1.7.1-streaming.1"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
// Generated by genversion. | ||
exports.version = "1.7.0"; | ||
exports.version = "1.7.1-streaming.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 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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
607382
128
6404
11
1
9
+ Addedqueue-microtask@^1.2.3
+ Addedqueue-microtask@1.2.3(transitive)