inngest 1.7.1 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/cloudflare.d.ts +2 -1
  3. package/cloudflare.d.ts.map +1 -1
  4. package/cloudflare.js.map +1 -1
  5. package/components/Inngest.d.ts +0 -7
  6. package/components/Inngest.d.ts.map +1 -1
  7. package/components/Inngest.js +33 -21
  8. package/components/Inngest.js.map +1 -1
  9. package/components/InngestCommHandler.d.ts +35 -8
  10. package/components/InngestCommHandler.d.ts.map +1 -1
  11. package/components/InngestCommHandler.js +122 -20
  12. package/components/InngestCommHandler.js.map +1 -1
  13. package/components/InngestFunction.d.ts.map +1 -1
  14. package/components/InngestFunction.js +4 -0
  15. package/components/InngestFunction.js.map +1 -1
  16. package/components/InngestStepTools.d.ts.map +1 -1
  17. package/components/InngestStepTools.js +2 -0
  18. package/components/InngestStepTools.js.map +1 -1
  19. package/deno/fresh.d.ts +2 -1
  20. package/deno/fresh.d.ts.map +1 -1
  21. package/deno/fresh.js.map +1 -1
  22. package/digitalocean.d.ts +3 -1
  23. package/digitalocean.d.ts.map +1 -1
  24. package/digitalocean.js +4 -3
  25. package/digitalocean.js.map +1 -1
  26. package/edge.d.ts +2 -1
  27. package/edge.d.ts.map +1 -1
  28. package/edge.js.map +1 -1
  29. package/express.d.ts +2 -1
  30. package/express.d.ts.map +1 -1
  31. package/express.js.map +1 -1
  32. package/helpers/env.d.ts +14 -0
  33. package/helpers/env.d.ts.map +1 -1
  34. package/helpers/env.js +84 -8
  35. package/helpers/env.js.map +1 -1
  36. package/helpers/errors.d.ts +58 -0
  37. package/helpers/errors.d.ts.map +1 -1
  38. package/helpers/errors.js +46 -1
  39. package/helpers/errors.js.map +1 -1
  40. package/helpers/functions.d.ts +6 -0
  41. package/helpers/functions.d.ts.map +1 -0
  42. package/helpers/functions.js +19 -0
  43. package/helpers/functions.js.map +1 -0
  44. package/helpers/promises.d.ts.map +1 -1
  45. package/helpers/promises.js +10 -14
  46. package/helpers/promises.js.map +1 -1
  47. package/helpers/stream.d.ts +25 -0
  48. package/helpers/stream.d.ts.map +1 -0
  49. package/helpers/stream.js +53 -0
  50. package/helpers/stream.js.map +1 -0
  51. package/lambda.d.ts +2 -1
  52. package/lambda.d.ts.map +1 -1
  53. package/lambda.js +2 -1
  54. package/lambda.js.map +1 -1
  55. package/landing.d.ts +1 -1
  56. package/landing.d.ts.map +1 -1
  57. package/landing.js +1 -1
  58. package/landing.js.map +1 -1
  59. package/next.d.ts +13 -2
  60. package/next.d.ts.map +1 -1
  61. package/next.js +117 -18
  62. package/next.js.map +1 -1
  63. package/nuxt.d.ts +2 -1
  64. package/nuxt.d.ts.map +1 -1
  65. package/nuxt.js.map +1 -1
  66. package/package.json +4 -2
  67. package/redwood.d.ts +2 -1
  68. package/redwood.d.ts.map +1 -1
  69. package/redwood.js.map +1 -1
  70. package/remix.d.ts +2 -1
  71. package/remix.d.ts.map +1 -1
  72. package/remix.js.map +1 -1
  73. package/types.d.ts +25 -0
  74. package/types.d.ts.map +1 -1
  75. package/version.d.ts +1 -1
  76. package/version.js +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # inngest
2
2
 
3
+ ## 1.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 5573be3: INN-1270 Create an internal handler to enforce more actionable user-facing errors
8
+
9
+ ## 1.8.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 65966f5: INN-1087 Add edge streaming support to `"inngest/next"` serve handler
14
+
15
+ ### Patch Changes
16
+
17
+ - 164fd5c: INN-1266 Fix bad link for fetching Inngest signing key on landing page
18
+
3
19
  ## 1.7.1
4
20
 
5
21
  ### Patch Changes
package/cloudflare.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ServeHandler } from "./components/InngestCommHandler";
2
- export declare const name = "cloudflare-pages";
2
+ import type { SupportedFrameworkName } from "./types";
3
+ export declare const name: SupportedFrameworkName;
3
4
  /**
4
5
  * In Cloudflare, serve and register any declared functions with Inngest, making
5
6
  * them available to be triggered by events.
@@ -1 +1 @@
1
- {"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../src/cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACb,MAAM,iCAAiC,CAAC;AAGzC,eAAO,MAAM,IAAI,qBAAqB,CAAC;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,YA6DnB,CAAC"}
1
+ {"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../src/cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACb,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD,eAAO,MAAM,IAAI,EAAE,sBAA2C,CAAC;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,YA6DnB,CAAC"}
package/cloudflare.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cloudflare.js","sourceRoot":"","sources":["../src/cloudflare.ts"],"names":[],"mappings":";;;AAAA,wEAGyC;AACzC,6CAAyD;AAE5C,QAAA,IAAI,GAAG,kBAAkB,CAAC;AAEvC;;;;;GAKG;AACI,MAAM,KAAK,GAAiB,CAAC,aAAa,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IAC9D,MAAM,OAAO,GAAG,IAAI,uCAAkB,CACpC,YAAI,EACJ,aAAa,EACb,GAAG;QAED;;;;WAIG;QACH,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,IAC1B,IAAI,GAET,CAAC,EACC,OAAO,EAAE,GAAG,EACZ,GAAG,GAIJ,EAAE,EAAE;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,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AAS,CAAC,MAAM,CAAW;wBACxD,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAA4B;wBACnD,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAU,CAAC,SAAS,CAAC,IAAI,SAAS;qBAC9D,CAAC;iBACH;YACH,CAAC;SACF,CAAC;IACJ,CAAC,EACD,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAY,EAAE;QACtC,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;YACxB,MAAM;YACN,OAAO;SACR,CAAC,CAAC;IACL,CAAC,CACF,CAAC;IAEF,OAAO,OAAO,CAAC,aAAa,EAAE,CAAC;AACjC,CAAC,CAAC;AA7DW,QAAA,KAAK,SA6DhB"}
@@ -1,8 +1,6 @@
1
1
  import type { PartialK, SendEventPayload, SingleOrArray } from "../helpers/types";
2
2
  import type { ClientOptions, EventNameFromTrigger, EventPayload, FailureEventArgs, FunctionOptions, Handler, ShimmedFns, TriggerOptions } from "../types";
3
3
  import { InngestFunction } from "./InngestFunction";
4
- export declare const eventKeyWarning = "Could not find an event key to send events; sending will throw unless an event key is added. Please pass one to the constructor, set the INNGEST_EVENT_KEY environment variable, or use inngest.setEventKey() at runtime.";
5
- export declare const eventKeyError = "Could not find an event key to send events. Please pass one to the constructor, set the INNGEST_EVENT_KEY environment variable, or use inngest.setEventKey() at runtime.";
6
4
  /**
7
5
  * A client used to interact with the Inngest API by sending or reacting to
8
6
  * events.
@@ -73,11 +71,6 @@ export declare class Inngest<Events extends Record<string, EventPayload> = Recor
73
71
  * ```
74
72
  */
75
73
  constructor({ name, eventKey, inngestBaseUrl, fetch, env, }: ClientOptions);
76
- /**
77
- * Given a potential fetch function, return the fetch function to use based on
78
- * this and the environment.
79
- */
80
- private static parseFetch;
81
74
  /**
82
75
  * Set the event key for this instance of Inngest. This is useful if for some
83
76
  * reason the key is not available at time of instantiation or present in the
@@ -1 +1 @@
1
- {"version":3,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E,OAAO,GACf,OAAO,CAAC,IAAI,CAAC;IAuGT,cAAc,CACnB,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,QAAQ,SAAS,cAAc,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,EACtD,WAAW,SAAS,MAAM,CACxB,MAAM,EAEN,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CACxB,GAAG,UAAU,CAAC,IAAI,CAAC,EACpB,YAAY,SAAS,MAAM,MAAM,GAAG,MAAM,GAAG,oBAAoB,CAC/D,MAAM,EACN,QAAQ,CACT,EAED,UAAU,EACN,MAAM,GACN,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,KAAK,GAAG,WAAW,CAAC,GAAG;QAClE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA+BG;QACH,GAAG,CAAC,EAAE,IAAI,CAAC;QAEX;;;;;;;WAOG;QACH,SAAS,CAAC,EAAE,OAAO,CACjB,MAAM,EACN,YAAY,EACZ,WAAW,EACX,gBAAgB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CACvC,CAAC;KACH,CAAC,EACN,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,WAAW,CAAC,GAClD,eAAe;CAYnB"}
@@ -6,13 +6,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
6
6
  };
7
7
  var _Inngest_instances, _Inngest_getResponseError;
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.Inngest = exports.eventKeyError = exports.eventKeyWarning = void 0;
9
+ exports.Inngest = void 0;
10
10
  const consts_1 = require("../helpers/consts");
11
11
  const devserver_1 = require("../helpers/devserver");
12
12
  const env_1 = require("../helpers/env");
13
+ const errors_1 = require("../helpers/errors");
13
14
  const InngestFunction_1 = require("./InngestFunction");
14
- exports.eventKeyWarning = "Could not find an event key to send events; sending will throw unless an event key is added. Please pass one to the constructor, set the INNGEST_EVENT_KEY environment variable, or use inngest.setEventKey() at runtime.";
15
- exports.eventKeyError = "Could not find an event key to send events. Please pass one to the constructor, set the INNGEST_EVENT_KEY environment variable, or use inngest.setEventKey() at runtime.";
16
15
  /**
17
16
  * A client used to interact with the Inngest API by sending or reacting to
18
17
  * events.
@@ -73,32 +72,30 @@ class Inngest {
73
72
  */
74
73
  this.inngestApiUrl = new URL(`e/${this.eventKey}`, "https://inn.gs/");
75
74
  if (!name) {
75
+ // TODO PrettyError
76
76
  throw new Error("A name must be passed to create an Inngest instance.");
77
77
  }
78
78
  this.name = name;
79
79
  this.inngestBaseUrl = new URL(inngestBaseUrl);
80
80
  this.setEventKey(eventKey || (0, env_1.processEnv)(consts_1.envKeys.EventKey) || "");
81
81
  if (!this.eventKey) {
82
- console.warn(exports.eventKeyWarning);
82
+ console.warn((0, errors_1.prettyError)({
83
+ type: "warn",
84
+ whatHappened: "Could not find event key",
85
+ consequences: "Sending events will throw in production unless an event key is added.",
86
+ toFixNow: [
87
+ "Pass a key to the `new Inngest()` constructor using the `eventKey` option",
88
+ "Set the `INNGEST_EVENT_KEY` environment variable",
89
+ "Use `inngest.setEventKey()` at runtime",
90
+ ],
91
+ why: "We couldn't find an event key to use to send events to Inngest.",
92
+ otherwise: "Create a new production event key at https://app.inngest.com/env/production/manage/keys.",
93
+ }));
83
94
  }
84
95
  this.headers = (0, env_1.inngestHeaders)({
85
96
  inngestEnv: env,
86
97
  });
87
- this.fetch = Inngest.parseFetch(fetch);
88
- }
89
- /**
90
- * Given a potential fetch function, return the fetch function to use based on
91
- * this and the environment.
92
- */
93
- static parseFetch(fetchArg) {
94
- if (fetchArg) {
95
- return fetchArg;
96
- }
97
- if (typeof fetch !== "undefined") {
98
- return fetch;
99
- }
100
- // eslint-disable-next-line @typescript-eslint/no-var-requires
101
- return require("cross-fetch");
98
+ this.fetch = (0, env_1.getFetch)(fetch);
102
99
  }
103
100
  /**
104
101
  * Set the event key for this instance of Inngest. This is useful if for some
@@ -117,7 +114,16 @@ class Inngest {
117
114
  }
118
115
  async send(nameOrPayload, maybePayload) {
119
116
  if (!this.eventKey) {
120
- throw new Error(exports.eventKeyError);
117
+ throw new Error((0, errors_1.prettyError)({
118
+ whatHappened: "Failed to send event",
119
+ consequences: "Your event or events were not sent to Inngest.",
120
+ why: "We couldn't find an event key to use to send events to Inngest.",
121
+ toFixNow: [
122
+ `Pass a key to the \`new Inngest()\` constructor using the \`${"eventKey"}\` option`,
123
+ "Set the `INNGEST_EVENT_KEY` environment variable",
124
+ `Use \`inngest.${"setEventKey"}()\` at runtime`,
125
+ ],
126
+ }));
121
127
  }
122
128
  let payloads;
123
129
  if (typeof nameOrPayload === "string") {
@@ -145,7 +151,13 @@ class Inngest {
145
151
  * happens, show a warning that this may not be intended, but don't throw.
146
152
  */
147
153
  if (!payloads.length) {
148
- return console.warn("Warning: You have called `inngest.send()` with an empty array; the operation will resolve, but no events have been sent. This may be intentional, in which case you can ignore this warning.");
154
+ return console.warn((0, errors_1.prettyError)({
155
+ type: "warn",
156
+ whatHappened: "`inngest.send()` called with no events",
157
+ reassurance: "This is not an error, but you may not have intended to do this.",
158
+ consequences: "The returned promise will resolve, but no events have been sent to Inngest.",
159
+ stack: true,
160
+ }));
149
161
  }
150
162
  // When sending events, check if the dev server is available. If so, use the
151
163
  // dev server.
@@ -1 +1 @@
1
- {"version":3,"file":"Inngest.js","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA4C;AAC5C,oDAAwE;AACxE,wCAKwB;AAiBxB,uDAAoD;AAOvC,QAAA,eAAe,GAC1B,2NAA2N,CAAC;AAEjN,QAAA,aAAa,GACxB,0KAA0K,CAAC;AAE7K;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,OAAO;IA4BlB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,YAAY,EACV,IAAI,EACJ,QAAQ,EACR,cAAc,GA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D,MAAM;QACR,KAAK,GAAG,CAAC;QACT,KAAK,GAAG;YACN,YAAY,GAAG,6BAA6B,CAAC;YAC7C,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,yBAAyB,CAAC;YACzC,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,uBAAuB,CAAC;YACvC,MAAM;KACT;IACD,OAAO,IAAI,KAAK,CAAC,sBAAsB,QAAQ,CAAC,MAAM,IAAI,YAAY,EAAE,CAAC,CAAC;AAC5E,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { ServerTiming } from "../helpers/ServerTiming";
2
2
  import type { MaybePromise } from "../helpers/types";
3
3
  import { FunctionConfig, LogLevel, RegisterOptions, RegisterRequest, StepRunResponse } from "../types";
4
- import type { Inngest } from "./Inngest";
4
+ import { Inngest } from "./Inngest";
5
5
  import type { InngestFunction } from "./InngestFunction";
6
6
  /**
7
7
  * A handler for serving Inngest functions. This type should be used
@@ -91,7 +91,7 @@ opts?: RegisterOptions
91
91
  *
92
92
  * @public
93
93
  */
94
- export declare class InngestCommHandler<H extends Handler, TransformedRes> {
94
+ 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> {
95
95
  /**
96
96
  * The name of this serve handler, e.g. `"My App"`. It's recommended that this
97
97
  * value represents the overarching app/service that this set of functions is
@@ -105,7 +105,8 @@ export declare class InngestCommHandler<H extends Handler, TransformedRes> {
105
105
  /**
106
106
  * The response transformer specified during instantiation of the class.
107
107
  */
108
- readonly transformRes: (res: ActionResponse, ...args: Parameters<H>) => TransformedRes;
108
+ readonly transformRes: TResTransform;
109
+ readonly streamTransformRes: TStreamTransform | undefined;
109
110
  /**
110
111
  * The URL of the Inngest function registration endpoint.
111
112
  */
@@ -176,6 +177,7 @@ export declare class InngestCommHandler<H extends Handler, TransformedRes> {
176
177
  * The minimum level to log from the Inngest serve handler.
177
178
  */
178
179
  protected readonly logLevel: LogLevel;
180
+ protected readonly streaming: RegisterOptions["streaming"];
179
181
  /**
180
182
  * A private collection of just Inngest functions, as they have been passed
181
183
  * when instantiating the class.
@@ -210,7 +212,7 @@ export declare class InngestCommHandler<H extends Handler, TransformedRes> {
210
212
  /**
211
213
  * An array of the functions to serve and register with Inngest.
212
214
  */
213
- functions: InngestFunction<any, any, any>[], { inngestRegisterUrl, fetch, landingPage, logLevel, signingKey, serveHost, servePath, }: RegisterOptions | undefined,
215
+ functions: InngestFunction<any, any, any>[], { inngestRegisterUrl, fetch, landingPage, logLevel, signingKey, serveHost, servePath, streaming, }: RegisterOptions | undefined,
214
216
  /**
215
217
  * The `handler` is the function your framework requires to handle a
216
218
  * request. For example, this is most commonly a function that is given a
@@ -260,7 +262,32 @@ export declare class InngestCommHandler<H extends Handler, TransformedRes> {
260
262
  * This should never be defined by the user; a {@link ServeHandler} should
261
263
  * abstract this.
262
264
  */
263
- transformRes: (actionRes: ActionResponse, ...args: Parameters<H>) => TransformedRes);
265
+ transformRes: TResTransform,
266
+ /**
267
+ * The `streamTransformRes` function, if defined, declares that this handler
268
+ * supports streaming responses back to Inngest. This is useful for
269
+ * functions that are expected to take a long time, as edge streaming can
270
+ * often circumvent restrictive request timeouts and other limitations.
271
+ *
272
+ * If your handler does not support streaming, do not define this function.
273
+ *
274
+ * It receives the output of the Inngest SDK and can decide how to package
275
+ * up that information to appropriately return the information in a stream
276
+ * to Inngest.
277
+ *
278
+ * Mostly, this is taking the given parameters and returning a new
279
+ * `Response`.
280
+ *
281
+ * The function is passed an {@link ActionResponse} (an object containing a
282
+ * `status` code, a `headers` object, and `body`, a `ReadableStream`), as
283
+ * well as every parameter passed to the given `handler` function. This
284
+ * ensures you can appropriately handle the response, including use of any
285
+ * required parameters such as `res` in Express-/Connect-like frameworks.
286
+ *
287
+ * This should never be defined by the user; a {@link ServeHandler} should
288
+ * abstract this.
289
+ */
290
+ streamTransformRes?: TStreamTransform);
264
291
  private get hashedSigningKey();
265
292
  /**
266
293
  * `createHandler` should be used to return a type-equivalent version of the
@@ -285,7 +312,7 @@ export declare class InngestCommHandler<H extends Handler, TransformedRes> {
285
312
  * };
286
313
  * ```
287
314
  */
288
- createHandler(): (...args: Parameters<H>) => Promise<TransformedRes>;
315
+ createHandler(): (...args: Parameters<H>) => Promise<Awaited<ReturnType<TResTransform>>>;
289
316
  /**
290
317
  * Given a set of functions to check if an action is available from the
291
318
  * instance's handler, enact any action that is found.
@@ -346,7 +373,7 @@ type Handler = (...args: any[]) => {
346
373
  * The response from the Inngest SDK before it is transformed in to a
347
374
  * framework-compatible response by an {@link InngestCommHandler} instance.
348
375
  */
349
- export interface ActionResponse {
376
+ export interface ActionResponse<TBody extends string | ReadableStream = string> {
350
377
  /**
351
378
  * The HTTP status code to return.
352
379
  */
@@ -358,7 +385,7 @@ export interface ActionResponse {
358
385
  /**
359
386
  * A stringified body to return.
360
387
  */
361
- body: string;
388
+ body: TBody;
362
389
  }
363
390
  /**
364
391
  * A set of actions the SDK is aware of, including any payloads they require
@@ -1 +1 @@
1
- {"version":3,"file":"InngestCommHandler.d.ts","sourceRoot":"","sources":["../../src/components/InngestCommHandler.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAOvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EACL,cAAc,EAGd,QAAQ,EACR,eAAe,EACf,eAAe,EACf,eAAe,EAChB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,YAAY,GAAG;AACzB;;;GAGG;AAEH,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;AAEpC;;GAEG;AAEH,SAAS,EA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EhC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,KAAK,aAAa,GACd;IACE,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,GACD;IACE,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,OAAO,CAAC;CAC1B,GACD;IACE,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;CAC1B,GACD;IACE,MAAM,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,GACD;IACE,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC"}
1
+ {"version":3,"file":"InngestCommHandler.d.ts","sourceRoot":"","sources":["../../src/components/InngestCommHandler.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAevD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EACL,cAAc,EAGd,QAAQ,EACR,eAAe,EACf,eAAe,EACf,eAAe,EAEhB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,YAAY,GAAG;AACzB;;;GAGG;AAEH,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;AAEpC;;GAEG;AAEH,SAAS,EAAE,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE;AAE3C;;;GAGG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,EAAE;QAAE,MAAM,EAAE,CAAC,CAAA;KAAE,CAAC,EAAE,QAAQ,CAAC,GAAG,SAAS,CAClE;CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,cAAc,CAC7B,KAAK,SAAS,MAAM,GAAG,cAAc,GAAG,MAAM;IAE9C;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhC;;OAEG;IACH,IAAI,EAAE,KAAK,CAAC;CACb;AAED;;;GAGG;AACH,KAAK,aAAa,GACd;IACE,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,GACD;IACE,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,OAAO,CAAC;CAC1B,GACD;IACE,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;CAC1B,GACD;IACE,MAAM,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,GACD;IACE,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC"}
@@ -12,7 +12,9 @@ const consts_1 = require("../helpers/consts");
12
12
  const devserver_1 = require("../helpers/devserver");
13
13
  const env_1 = require("../helpers/env");
14
14
  const errors_1 = require("../helpers/errors");
15
+ const functions_1 = require("../helpers/functions");
15
16
  const scalar_1 = require("../helpers/scalar");
17
+ const stream_1 = require("../helpers/stream");
16
18
  const strings_1 = require("../helpers/strings");
17
19
  const landing_1 = require("../landing");
18
20
  const version_1 = require("../version");
@@ -86,7 +88,7 @@ class InngestCommHandler {
86
88
  * An array of the functions to serve and register with Inngest.
87
89
  */
88
90
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
- functions, { inngestRegisterUrl, fetch, landingPage, logLevel = "info", signingKey, serveHost, servePath, } = {},
91
+ functions, { inngestRegisterUrl, fetch, landingPage, logLevel = "info", signingKey, serveHost, servePath, streaming, } = {},
90
92
  /**
91
93
  * The `handler` is the function your framework requires to handle a
92
94
  * request. For example, this is most commonly a function that is given a
@@ -136,7 +138,32 @@ class InngestCommHandler {
136
138
  * This should never be defined by the user; a {@link ServeHandler} should
137
139
  * abstract this.
138
140
  */
139
- transformRes) {
141
+ transformRes,
142
+ /**
143
+ * The `streamTransformRes` function, if defined, declares that this handler
144
+ * supports streaming responses back to Inngest. This is useful for
145
+ * functions that are expected to take a long time, as edge streaming can
146
+ * often circumvent restrictive request timeouts and other limitations.
147
+ *
148
+ * If your handler does not support streaming, do not define this function.
149
+ *
150
+ * It receives the output of the Inngest SDK and can decide how to package
151
+ * up that information to appropriately return the information in a stream
152
+ * to Inngest.
153
+ *
154
+ * Mostly, this is taking the given parameters and returning a new
155
+ * `Response`.
156
+ *
157
+ * The function is passed an {@link ActionResponse} (an object containing a
158
+ * `status` code, a `headers` object, and `body`, a `ReadableStream`), as
159
+ * well as every parameter passed to the given `handler` function. This
160
+ * ensures you can appropriately handle the response, including use of any
161
+ * required parameters such as `res` in Express-/Connect-like frameworks.
162
+ *
163
+ * This should never be defined by the user; a {@link ServeHandler} should
164
+ * abstract this.
165
+ */
166
+ streamTransformRes) {
140
167
  var _a;
141
168
  /**
142
169
  * A property that can be set to indicate whether or not we believe we are in
@@ -157,6 +184,7 @@ class InngestCommHandler {
157
184
  : appNameOrInngest.name;
158
185
  this.handler = handler;
159
186
  this.transformRes = transformRes;
187
+ this.streamTransformRes = streamTransformRes;
160
188
  /**
161
189
  * Provide a hidden option to allow expired signatures to be accepted during
162
190
  * testing.
@@ -167,6 +195,7 @@ class InngestCommHandler {
167
195
  // Ensure we filter any undefined functions in case of missing imports.
168
196
  this.rawFns = functions.filter(Boolean);
169
197
  if (this.rawFns.length !== functions.length) {
198
+ // TODO PrettyError
170
199
  console.warn(`Some functions passed to serve() are undefined and misconfigured. Please check your imports.`);
171
200
  }
172
201
  this.fns = this.rawFns.reduce((acc, fn) => {
@@ -176,6 +205,7 @@ class InngestCommHandler {
176
205
  }, {});
177
206
  configs.forEach(({ id }) => {
178
207
  if (acc[id]) {
208
+ // TODO PrettyError
179
209
  throw new Error(`Duplicate function ID "${id}"; please change a function's name or provide an explicit ID to avoid conflicts.`);
180
210
  }
181
211
  });
@@ -187,13 +217,11 @@ class InngestCommHandler {
187
217
  this.serveHost = serveHost;
188
218
  this.servePath = servePath;
189
219
  this.logLevel = logLevel;
190
- this.fetch =
191
- fetch ||
192
- (typeof appNameOrInngest === "string"
193
- ? undefined
194
- : appNameOrInngest["fetch"]) ||
195
- // eslint-disable-next-line @typescript-eslint/no-var-requires
196
- require("cross-fetch");
220
+ this.streaming = streaming !== null && streaming !== void 0 ? streaming : false;
221
+ this.fetch = (0, env_1.getFetch)(fetch ||
222
+ (typeof appNameOrInngest === "string"
223
+ ? undefined
224
+ : appNameOrInngest["fetch"]));
197
225
  }
198
226
  // hashedSigningKey creates a sha256 checksum of the signing key with the
199
227
  // same signing key prefix.
@@ -238,9 +266,62 @@ class InngestCommHandler {
238
266
  * async.
239
267
  */
240
268
  // eslint-disable-next-line @typescript-eslint/await-thenable
241
- const actions = await timer.wrap("handler", () => this.handler(...args));
242
- const actionRes = await timer.wrap("action", () => this.handleAction(actions, timer));
243
- return timer.wrap("res", () => this.transformRes(actionRes, ...args));
269
+ const rawActions = await timer.wrap("handler", () => this.handler(...args));
270
+ /**
271
+ * For each function within the actions returned, ensure that its value
272
+ * caches when run. This ensures that the function is only run once, even
273
+ * if it's called multiple times throughout this handler's invocation.
274
+ *
275
+ * Many frameworks have issues with multiple calls to req/res objects;
276
+ * reading a request's body multiple times is a common example. This makes
277
+ * sure to handle this without having to pass around references.
278
+ */
279
+ const actions = Object.fromEntries(Object.entries(rawActions).map(([key, val]) => [
280
+ key,
281
+ typeof val === "function" ? (0, functions_1.cacheFn)(val) : val,
282
+ ]));
283
+ const getHeaders = () => (Object.assign(Object.assign({}, (0, env_1.inngestHeaders)({
284
+ env: actions.env,
285
+ framework: this.frameworkName,
286
+ })), { "Server-Timing": timer.getHeader() }));
287
+ const actionRes = timer.wrap("action", () => this.handleAction(actions, timer));
288
+ /**
289
+ * Prepares an action response by merging returned data to provide
290
+ * trailing information such as `Server-Timing` headers.
291
+ *
292
+ * It should always prioritize the headers returned by the action, as
293
+ * they may contain important information such as `Content-Type`.
294
+ */
295
+ const prepareActionRes = (res) => (Object.assign(Object.assign({}, res), { headers: Object.assign(Object.assign({}, getHeaders()), res.headers) }));
296
+ const wantToStream = this.streaming === "force" ||
297
+ (this.streaming === "allow" &&
298
+ (0, env_1.platformSupportsStreaming)(this.frameworkName, actions.env));
299
+ if (wantToStream && this.streamTransformRes) {
300
+ const runRes = await actions.run();
301
+ if (runRes) {
302
+ const { stream, finalize } = await (0, stream_1.createStream)();
303
+ /**
304
+ * Errors are handled by `handleAction` here to ensure that an
305
+ * appropriate response is always given.
306
+ */
307
+ void actionRes.then((res) => finalize(prepareActionRes(res)));
308
+ return timer.wrap("res", () => {
309
+ var _a;
310
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
311
+ return (_a = this.streamTransformRes) === null || _a === void 0 ? void 0 : _a.call(this, {
312
+ status: 201,
313
+ headers: getHeaders(),
314
+ body: stream,
315
+ }, ...args);
316
+ });
317
+ }
318
+ }
319
+ return timer.wrap("res", async () => {
320
+ return actionRes.then((res) => {
321
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
322
+ return this.transformRes(prepareActionRes(res), ...args);
323
+ });
324
+ });
244
325
  };
245
326
  }
246
327
  /**
@@ -273,13 +354,17 @@ class InngestCommHandler {
273
354
  status: stepRes.status,
274
355
  body: JSON.stringify(stepRes.error ||
275
356
  (0, errors_1.serializeError)(new Error("Unknown error; function failed but no error was returned"))),
276
- headers: Object.assign(Object.assign({}, getHeaders()), { "Content-Type": "application/json" }),
357
+ headers: {
358
+ "Content-Type": "application/json",
359
+ },
277
360
  };
278
361
  }
279
362
  return {
280
363
  status: stepRes.status,
281
364
  body: JSON.stringify(stepRes.body),
282
- headers: Object.assign(Object.assign({}, getHeaders()), { "Content-Type": "application/json" }),
365
+ headers: {
366
+ "Content-Type": "application/json",
367
+ },
283
368
  };
284
369
  }
285
370
  const viewRes = await actions.view();
@@ -290,7 +375,7 @@ class InngestCommHandler {
290
375
  return {
291
376
  status: 405,
292
377
  body: "",
293
- headers: getHeaders(),
378
+ headers: {},
294
379
  };
295
380
  }
296
381
  if (viewRes.isIntrospection) {
@@ -298,13 +383,17 @@ class InngestCommHandler {
298
383
  return {
299
384
  status: 200,
300
385
  body: JSON.stringify(introspection),
301
- headers: Object.assign(Object.assign({}, getHeaders()), { "Content-Type": "application/json" }),
386
+ headers: {
387
+ "Content-Type": "application/json",
388
+ },
302
389
  };
303
390
  }
304
391
  return {
305
392
  status: 200,
306
393
  body: landing_1.landing,
307
- headers: Object.assign(Object.assign({}, getHeaders()), { "Content-Type": "text/html; charset=utf-8" }),
394
+ headers: {
395
+ "Content-Type": "text/html; charset=utf-8",
396
+ },
308
397
  };
309
398
  }
310
399
  const registerRes = await actions.register();
@@ -314,7 +403,9 @@ class InngestCommHandler {
314
403
  return {
315
404
  status,
316
405
  body: JSON.stringify({ message }),
317
- headers: Object.assign(Object.assign({}, getHeaders()), { "Content-Type": "application/json" }),
406
+ headers: {
407
+ "Content-Type": "application/json",
408
+ },
318
409
  };
319
410
  }
320
411
  }
@@ -322,13 +413,15 @@ class InngestCommHandler {
322
413
  return {
323
414
  status: 500,
324
415
  body: JSON.stringify(Object.assign({ type: "internal" }, (0, errors_1.serializeError)(err))),
325
- headers: Object.assign(Object.assign({}, getHeaders()), { "Content-Type": "application/json" }),
416
+ headers: {
417
+ "Content-Type": "application/json",
418
+ },
326
419
  };
327
420
  }
328
421
  return {
329
422
  status: 405,
330
423
  body: "",
331
- headers: getHeaders(),
424
+ headers: {},
332
425
  };
333
426
  }
334
427
  async runStep(functionId, stepId, data, timer) {
@@ -336,8 +429,10 @@ class InngestCommHandler {
336
429
  try {
337
430
  const fn = this.fns[functionId];
338
431
  if (!fn) {
432
+ // TODO PrettyError
339
433
  throw new Error(`Could not find function with ID "${functionId}"`);
340
434
  }
435
+ // TODO PrettyError on parse failure; serve handler may be set up badly
341
436
  const { event, steps, ctx } = zod_1.z
342
437
  .object({
343
438
  event: zod_1.z.object({}).passthrough(),
@@ -385,6 +480,7 @@ class InngestCommHandler {
385
480
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
386
481
  const step = steps === null || steps === void 0 ? void 0 : steps[opId];
387
482
  if (typeof step === "undefined") {
483
+ // TODO PrettyError
388
484
  throw new Error(`Could not find step with ID "${opId}"`);
389
485
  }
390
486
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
@@ -546,16 +642,19 @@ class InngestCommHandler {
546
642
  if (!this.isProd) {
547
643
  // In dev, warning users about signing keys ensures that it's considered
548
644
  if (!this.signingKey) {
645
+ // TODO PrettyError
549
646
  console.warn("No signing key provided to validate signature. Find your dev keys at https://app.inngest.com/test/secrets");
550
647
  }
551
648
  return;
552
649
  }
553
650
  // If we're here, we're in production; lack of a signing key is an error.
554
651
  if (!this.signingKey) {
652
+ // TODO PrettyError
555
653
  throw new Error(`No signing key found in client options or ${consts_1.envKeys.SigningKey} env var. Find your keys at https://app.inngest.com/secrets`);
556
654
  }
557
655
  // If we're here, we're in production; lack of a req signature is an error.
558
656
  if (!sig) {
657
+ // TODO PrettyError
559
658
  throw new Error(`No ${consts_1.headerKeys.Signature} provided`);
560
659
  }
561
660
  // Validate the signature
@@ -603,6 +702,7 @@ class RequestSignature {
603
702
  this.timestamp = params.get("t") || "";
604
703
  this.signature = params.get("s") || "";
605
704
  if (!this.timestamp || !this.signature) {
705
+ // TODO PrettyError
606
706
  throw new Error(`Invalid ${consts_1.headerKeys.Signature} provided`);
607
707
  }
608
708
  }
@@ -615,6 +715,7 @@ class RequestSignature {
615
715
  }
616
716
  verifySignature({ body, signingKey, allowExpiredSignatures, }) {
617
717
  if (this.hasExpired(allowExpiredSignatures)) {
718
+ // TODO PrettyError
618
719
  throw new Error("Signature has expired");
619
720
  }
620
721
  // Calculate the HMAC of the request body ourselves.
@@ -630,6 +731,7 @@ class RequestSignature {
630
731
  .update(this.timestamp)
631
732
  .digest("hex");
632
733
  if (mac !== this.signature) {
734
+ // TODO PrettyError
633
735
  throw new Error("Invalid signature");
634
736
  }
635
737
  }