inngest 2.7.1 → 3.0.0
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.
- package/CHANGELOG.md +52 -0
- package/api/api.js +4 -4
- package/api/schema.d.ts +54 -6
- package/api/schema.d.ts.map +1 -1
- package/api/schema.js +17 -7
- package/api/schema.js.map +1 -1
- package/cloudflare.d.ts +6 -3
- package/cloudflare.d.ts.map +1 -1
- package/cloudflare.js +19 -41
- package/cloudflare.js.map +1 -1
- package/components/EventSchemas.d.ts +1 -12
- package/components/EventSchemas.d.ts.map +1 -1
- package/components/EventSchemas.js.map +1 -1
- package/components/Inngest.d.ts +44 -57
- package/components/Inngest.d.ts.map +1 -1
- package/components/Inngest.js +91 -59
- package/components/Inngest.js.map +1 -1
- package/components/InngestCommHandler.d.ts +156 -198
- package/components/InngestCommHandler.d.ts.map +1 -1
- package/components/InngestCommHandler.js +311 -305
- package/components/InngestCommHandler.js.map +1 -1
- package/components/InngestFunction.d.ts +9 -82
- package/components/InngestFunction.d.ts.map +1 -1
- package/components/InngestFunction.js +21 -413
- package/components/InngestFunction.js.map +1 -1
- package/components/InngestMiddleware.d.ts +37 -26
- package/components/InngestMiddleware.d.ts.map +1 -1
- package/components/InngestMiddleware.js +1 -3
- package/components/InngestMiddleware.js.map +1 -1
- package/components/InngestStepTools.d.ts +69 -37
- package/components/InngestStepTools.d.ts.map +1 -1
- package/components/InngestStepTools.js +34 -95
- package/components/InngestStepTools.js.map +1 -1
- package/components/NonRetriableError.d.ts.map +1 -1
- package/components/NonRetriableError.js +1 -0
- package/components/NonRetriableError.js.map +1 -1
- package/components/RetryAfterError.d.ts +38 -0
- package/components/RetryAfterError.d.ts.map +1 -0
- package/components/RetryAfterError.js +42 -0
- package/components/RetryAfterError.js.map +1 -0
- package/components/execution/InngestExecution.d.ts +72 -0
- package/components/execution/InngestExecution.d.ts.map +1 -0
- package/components/execution/InngestExecution.js +23 -0
- package/components/execution/InngestExecution.js.map +1 -0
- package/components/execution/v0.d.ts +114 -0
- package/components/execution/v0.d.ts.map +1 -0
- package/components/execution/v0.js +394 -0
- package/components/execution/v0.js.map +1 -0
- package/components/execution/v1.d.ts +88 -0
- package/components/execution/v1.d.ts.map +1 -0
- package/components/execution/v1.js +673 -0
- package/components/execution/v1.js.map +1 -0
- package/deno/fresh.d.ts +3 -3
- package/deno/fresh.d.ts.map +1 -1
- package/deno/fresh.js +17 -38
- package/deno/fresh.js.map +1 -1
- package/digitalocean.d.ts +5 -5
- package/digitalocean.d.ts.map +1 -1
- package/digitalocean.js +14 -46
- package/digitalocean.js.map +1 -1
- package/edge.d.ts +5 -5
- package/edge.d.ts.map +1 -1
- package/edge.js +16 -38
- package/edge.js.map +1 -1
- package/express.d.ts +7 -3
- package/express.d.ts.map +1 -1
- package/express.js +38 -45
- package/express.js.map +1 -1
- package/fastify.d.ts +8 -3
- package/fastify.d.ts.map +1 -1
- package/fastify.js +37 -47
- package/fastify.js.map +1 -1
- package/h3.d.ts +4 -3
- package/h3.d.ts.map +1 -1
- package/h3.js +18 -45
- package/h3.js.map +1 -1
- package/helpers/ServerTiming.d.ts.map +1 -1
- package/helpers/ServerTiming.js +2 -1
- package/helpers/ServerTiming.js.map +1 -1
- package/helpers/consts.d.ts +23 -9
- package/helpers/consts.d.ts.map +1 -1
- package/helpers/consts.js +31 -13
- package/helpers/consts.js.map +1 -1
- package/helpers/devserver.d.ts +0 -34
- package/helpers/devserver.d.ts.map +1 -1
- package/helpers/devserver.js.map +1 -1
- package/helpers/env.d.ts +14 -6
- package/helpers/env.d.ts.map +1 -1
- package/helpers/env.js +4 -4
- package/helpers/env.js.map +1 -1
- package/helpers/errors.d.ts +37 -2
- package/helpers/errors.d.ts.map +1 -1
- package/helpers/errors.js +66 -15
- package/helpers/errors.js.map +1 -1
- package/helpers/functions.d.ts +52 -5
- package/helpers/functions.d.ts.map +1 -1
- package/helpers/functions.js +121 -22
- package/helpers/functions.js.map +1 -1
- package/helpers/promises.d.ts +45 -0
- package/helpers/promises.d.ts.map +1 -1
- package/helpers/promises.js +69 -1
- package/helpers/promises.js.map +1 -1
- package/helpers/strings.d.ts +6 -1
- package/helpers/strings.d.ts.map +1 -1
- package/helpers/strings.js +7 -2
- package/helpers/strings.js.map +1 -1
- package/helpers/types.d.ts +5 -17
- package/helpers/types.d.ts.map +1 -1
- package/index.d.ts +4 -2
- package/index.d.ts.map +1 -1
- package/index.js +5 -1
- package/index.js.map +1 -1
- package/lambda.d.ts +10 -8
- package/lambda.d.ts.map +1 -1
- package/lambda.js +48 -72
- package/lambda.js.map +1 -1
- package/next.d.ts +11 -5
- package/next.d.ts.map +1 -1
- package/next.js +84 -103
- package/next.js.map +1 -1
- package/nuxt.d.ts +3 -3
- package/nuxt.d.ts.map +1 -1
- package/nuxt.js +5 -6
- package/nuxt.js.map +1 -1
- package/package.json +5 -4
- package/redwood.d.ts +4 -3
- package/redwood.d.ts.map +1 -1
- package/redwood.js +22 -48
- package/redwood.js.map +1 -1
- package/remix.d.ts +7 -5
- package/remix.d.ts.map +1 -1
- package/remix.js +15 -36
- package/remix.js.map +1 -1
- package/types.d.ts +150 -218
- package/types.d.ts.map +1 -1
- package/types.js +38 -45
- package/types.js.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/helpers/scalar.d.ts +0 -8
- package/helpers/scalar.d.ts.map +0 -1
- package/helpers/scalar.js +0 -19
- package/helpers/scalar.js.map +0 -1
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.InngestCommHandler = void 0;
|
|
7
7
|
const canonicalize_1 = __importDefault(require("canonicalize"));
|
|
8
|
+
const debug_1 = __importDefault(require("debug"));
|
|
8
9
|
const hash_js_1 = require("hash.js");
|
|
9
10
|
const zod_1 = require("zod");
|
|
10
11
|
const ServerTiming_1 = require("../helpers/ServerTiming");
|
|
@@ -13,10 +14,12 @@ const devserver_1 = require("../helpers/devserver");
|
|
|
13
14
|
const env_1 = require("../helpers/env");
|
|
14
15
|
const errors_1 = require("../helpers/errors");
|
|
15
16
|
const functions_1 = require("../helpers/functions");
|
|
17
|
+
const promises_1 = require("../helpers/promises");
|
|
16
18
|
const stream_1 = require("../helpers/stream");
|
|
17
19
|
const strings_1 = require("../helpers/strings");
|
|
20
|
+
const types_1 = require("../types");
|
|
18
21
|
const version_1 = require("../version");
|
|
19
|
-
const
|
|
22
|
+
const InngestExecution_1 = require("./execution/InngestExecution");
|
|
20
23
|
/**
|
|
21
24
|
* A schema for the response from Inngest when registering.
|
|
22
25
|
*/
|
|
@@ -62,108 +65,8 @@ const registerResSchema = zod_1.z.object({
|
|
|
62
65
|
* @public
|
|
63
66
|
*/
|
|
64
67
|
class InngestCommHandler {
|
|
65
|
-
constructor(
|
|
66
|
-
|
|
67
|
-
* The name of the framework this handler is designed for. Should be
|
|
68
|
-
* lowercase, alphanumeric characters inclusive of `-` and `/`.
|
|
69
|
-
*
|
|
70
|
-
* This should never be defined by the user; a {@link ServeHandler} should
|
|
71
|
-
* abstract this.
|
|
72
|
-
*/
|
|
73
|
-
frameworkName,
|
|
74
|
-
/**
|
|
75
|
-
* The name of this serve handler, e.g. `"My App"`. It's recommended that this
|
|
76
|
-
* value represents the overarching app/service that this set of functions is
|
|
77
|
-
* being served from.
|
|
78
|
-
*
|
|
79
|
-
* This can also be an `Inngest` client, in which case the name given when
|
|
80
|
-
* instantiating the client is used. This is useful if you're sending and
|
|
81
|
-
* receiving events from the same service, as you can reuse a single
|
|
82
|
-
* definition of Inngest.
|
|
83
|
-
*/
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
-
client,
|
|
86
|
-
/**
|
|
87
|
-
* An array of the functions to serve and register with Inngest.
|
|
88
|
-
*/
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
90
|
-
functions, options = {},
|
|
91
|
-
/**
|
|
92
|
-
* The `handler` is the function your framework requires to handle a
|
|
93
|
-
* request. For example, this is most commonly a function that is given a
|
|
94
|
-
* `Request` and must return a `Response`.
|
|
95
|
-
*
|
|
96
|
-
* The handler must map out any incoming parameters, then return a
|
|
97
|
-
* strictly-typed object to assess what kind of request is being made,
|
|
98
|
-
* collecting any relevant data as we go.
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```
|
|
102
|
-
* return {
|
|
103
|
-
* register: () => { ... },
|
|
104
|
-
* run: () => { ... },
|
|
105
|
-
* view: () => { ... }
|
|
106
|
-
* };
|
|
107
|
-
* ```
|
|
108
|
-
*
|
|
109
|
-
* Every key must be specified and must be a function that either returns
|
|
110
|
-
* a strictly-typed payload or `undefined` if the request is not for that
|
|
111
|
-
* purpose.
|
|
112
|
-
*
|
|
113
|
-
* This gives handlers freedom to choose how their platform of choice will
|
|
114
|
-
* trigger differing actions, whilst also ensuring all required information
|
|
115
|
-
* is given for each request type.
|
|
116
|
-
*
|
|
117
|
-
* See any existing handler for a full example.
|
|
118
|
-
*
|
|
119
|
-
* This should never be defined by the user; a {@link ServeHandler} should
|
|
120
|
-
* abstract this.
|
|
121
|
-
*/
|
|
122
|
-
handler,
|
|
123
|
-
/**
|
|
124
|
-
* The `transformRes` function receives the output of the Inngest SDK and
|
|
125
|
-
* can decide how to package up that information to appropriately return the
|
|
126
|
-
* information to Inngest.
|
|
127
|
-
*
|
|
128
|
-
* Mostly, this is taking the given parameters and returning a new
|
|
129
|
-
* `Response`.
|
|
130
|
-
*
|
|
131
|
-
* The function is passed an {@link ActionResponse} (an object containing a
|
|
132
|
-
* `status` code, a `headers` object, and a stringified `body`), as well as
|
|
133
|
-
* every parameter passed to the given `handler` function. This ensures you
|
|
134
|
-
* can appropriately handle the response, including use of any required
|
|
135
|
-
* parameters such as `res` in Express-/Connect-like frameworks.
|
|
136
|
-
*
|
|
137
|
-
* This should never be defined by the user; a {@link ServeHandler} should
|
|
138
|
-
* abstract this.
|
|
139
|
-
*/
|
|
140
|
-
transformRes,
|
|
141
|
-
/**
|
|
142
|
-
* The `streamTransformRes` function, if defined, declares that this handler
|
|
143
|
-
* supports streaming responses back to Inngest. This is useful for
|
|
144
|
-
* functions that are expected to take a long time, as edge streaming can
|
|
145
|
-
* often circumvent restrictive request timeouts and other limitations.
|
|
146
|
-
*
|
|
147
|
-
* If your handler does not support streaming, do not define this function.
|
|
148
|
-
*
|
|
149
|
-
* It receives the output of the Inngest SDK and can decide how to package
|
|
150
|
-
* up that information to appropriately return the information in a stream
|
|
151
|
-
* to Inngest.
|
|
152
|
-
*
|
|
153
|
-
* Mostly, this is taking the given parameters and returning a new
|
|
154
|
-
* `Response`.
|
|
155
|
-
*
|
|
156
|
-
* The function is passed an {@link ActionResponse} (an object containing a
|
|
157
|
-
* `status` code, a `headers` object, and `body`, a `ReadableStream`), as
|
|
158
|
-
* well as every parameter passed to the given `handler` function. This
|
|
159
|
-
* ensures you can appropriately handle the response, including use of any
|
|
160
|
-
* required parameters such as `res` in Express-/Connect-like frameworks.
|
|
161
|
-
*
|
|
162
|
-
* This should never be defined by the user; a {@link ServeHandler} should
|
|
163
|
-
* abstract this.
|
|
164
|
-
*/
|
|
165
|
-
streamTransformRes) {
|
|
166
|
-
var _a, _b, _c;
|
|
68
|
+
constructor(options) {
|
|
69
|
+
var _a;
|
|
167
70
|
/**
|
|
168
71
|
* A property that can be set to indicate whether or not we believe we are in
|
|
169
72
|
* production mode.
|
|
@@ -182,28 +85,36 @@ class InngestCommHandler {
|
|
|
182
85
|
* to find and register functions when interacting with Inngest Cloud.
|
|
183
86
|
*/
|
|
184
87
|
this.fns = {};
|
|
185
|
-
this.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
88
|
+
this.env = (0, env_1.allProcessEnv)();
|
|
89
|
+
/**
|
|
90
|
+
* v2 -> v3 migration error.
|
|
91
|
+
*
|
|
92
|
+
* If a serve handler is passed a client as the first argument, it'll be
|
|
93
|
+
* spread in to these options. We should be able to detect this by picking
|
|
94
|
+
* up a unique property on the object.
|
|
95
|
+
*/
|
|
96
|
+
if (Object.prototype.hasOwnProperty.call(options, "eventKey")) {
|
|
97
|
+
throw new Error(`${consts_1.logPrefix} You've passed an Inngest client as the first argument to your serve handler. This is no longer supported in v3; please pass the Inngest client as the \`client\` property of an options object instead. See https://www.inngest.com/docs/sdk/migration`);
|
|
98
|
+
}
|
|
99
|
+
this.frameworkName = options.frameworkName;
|
|
100
|
+
this.client = options.client;
|
|
101
|
+
this.id = options.id || this.client.id;
|
|
102
|
+
this.handler = options.handler;
|
|
192
103
|
/**
|
|
193
104
|
* Provide a hidden option to allow expired signatures to be accepted during
|
|
194
105
|
* testing.
|
|
195
106
|
*/
|
|
196
107
|
this.allowExpiredSignatures = Boolean(
|
|
197
108
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, prefer-rest-params
|
|
198
|
-
(_a = arguments["
|
|
109
|
+
(_a = arguments["0"]) === null || _a === void 0 ? void 0 : _a.__testingAllowExpiredSignatures);
|
|
199
110
|
// Ensure we filter any undefined functions in case of missing imports.
|
|
200
|
-
this.rawFns = functions.filter(Boolean);
|
|
201
|
-
if (this.rawFns.length !== functions.length) {
|
|
111
|
+
this.rawFns = options.functions.filter(Boolean);
|
|
112
|
+
if (this.rawFns.length !== options.functions.length) {
|
|
202
113
|
// TODO PrettyError
|
|
203
114
|
console.warn(`Some functions passed to serve() are undefined and misconfigured. Please check your imports.`);
|
|
204
115
|
}
|
|
205
116
|
this.fns = this.rawFns.reduce((acc, fn) => {
|
|
206
|
-
const configs = fn["getConfig"](new URL("https://example.com"), this.
|
|
117
|
+
const configs = fn["getConfig"](new URL("https://example.com"), this.id);
|
|
207
118
|
const fns = configs.reduce((acc, { id }, index) => {
|
|
208
119
|
return Object.assign(Object.assign({}, acc), { [id]: { fn, onFailure: Boolean(index) } });
|
|
209
120
|
}, {});
|
|
@@ -215,12 +126,34 @@ class InngestCommHandler {
|
|
|
215
126
|
});
|
|
216
127
|
return Object.assign(Object.assign({}, acc), fns);
|
|
217
128
|
}, {});
|
|
218
|
-
this.inngestRegisterUrl = new URL(
|
|
129
|
+
this.inngestRegisterUrl = new URL("/fn/register", options.baseUrl ||
|
|
130
|
+
this.env[consts_1.envKeys.InngestBaseUrl] ||
|
|
131
|
+
this.client["baseUrl"] ||
|
|
132
|
+
consts_1.defaultInngestBaseUrl);
|
|
219
133
|
this.signingKey = options.signingKey;
|
|
220
|
-
this.serveHost = options.serveHost;
|
|
221
|
-
this.servePath = options.servePath;
|
|
222
|
-
|
|
223
|
-
this.
|
|
134
|
+
this.serveHost = options.serveHost || this.env[consts_1.envKeys.InngestServeHost];
|
|
135
|
+
this.servePath = options.servePath || this.env[consts_1.envKeys.InngestServePath];
|
|
136
|
+
const defaultLogLevel = "info";
|
|
137
|
+
this.logLevel = zod_1.z
|
|
138
|
+
.enum(types_1.logLevels)
|
|
139
|
+
.default(defaultLogLevel)
|
|
140
|
+
.catch((ctx) => {
|
|
141
|
+
this.log("warn", `Unknown log level passed: ${String(ctx.input)}; defaulting to ${defaultLogLevel}`);
|
|
142
|
+
return defaultLogLevel;
|
|
143
|
+
})
|
|
144
|
+
.parse(options.logLevel || this.env[consts_1.envKeys.InngestLogLevel]);
|
|
145
|
+
if (this.logLevel === "debug") {
|
|
146
|
+
debug_1.default.enable(`${consts_1.debugPrefix}:*`);
|
|
147
|
+
}
|
|
148
|
+
const defaultStreamingOption = false;
|
|
149
|
+
this.streaming = zod_1.z
|
|
150
|
+
.union([zod_1.z.enum(["allow", "force"]), zod_1.z.literal(false)])
|
|
151
|
+
.default(defaultStreamingOption)
|
|
152
|
+
.catch((ctx) => {
|
|
153
|
+
this.log("warn", `Unknown streaming option passed: ${String(ctx.input)}; defaulting to ${String(defaultStreamingOption)}`);
|
|
154
|
+
return defaultStreamingOption;
|
|
155
|
+
})
|
|
156
|
+
.parse(options.streaming || this.env[consts_1.envKeys.InngestStreaming]);
|
|
224
157
|
this.fetch = (0, env_1.getFetch)(options.fetch || this.client["fetch"]);
|
|
225
158
|
}
|
|
226
159
|
// hashedSigningKey creates a sha256 checksum of the signing key with the
|
|
@@ -253,35 +186,54 @@ class InngestCommHandler {
|
|
|
253
186
|
*/
|
|
254
187
|
createHandler() {
|
|
255
188
|
return async (...args) => {
|
|
189
|
+
var _a, _b;
|
|
256
190
|
const timer = new ServerTiming_1.ServerTiming();
|
|
257
191
|
/**
|
|
258
192
|
* We purposefully `await` the handler, as it could be either sync or
|
|
259
193
|
* async.
|
|
260
194
|
*/
|
|
261
|
-
|
|
262
|
-
|
|
195
|
+
const rawActions = await timer
|
|
196
|
+
.wrap("handler", () => this.handler(...args))
|
|
197
|
+
.catch((0, errors_1.rethrowError)("Serve handler failed to run"));
|
|
263
198
|
/**
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
199
|
+
* Map over every `action` in `rawActions` and create a new `actions`
|
|
200
|
+
* object where each function is safely promisifed with each access
|
|
201
|
+
* requiring a reason.
|
|
267
202
|
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* sure to handle this without having to pass around references.
|
|
203
|
+
* This helps us provide high quality errors about what's going wrong for
|
|
204
|
+
* each access without having to wrap every access in a try/catch.
|
|
271
205
|
*/
|
|
272
|
-
const actions = Object.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
206
|
+
const actions = Object.entries(rawActions).reduce((acc, [key, value]) => {
|
|
207
|
+
if (typeof value !== "function") {
|
|
208
|
+
return acc;
|
|
209
|
+
}
|
|
210
|
+
return Object.assign(Object.assign({}, acc), { [key]: (reason, ...args) => {
|
|
211
|
+
const errMessage = [
|
|
212
|
+
`Failed calling \`${key}\` from serve handler`,
|
|
213
|
+
reason,
|
|
214
|
+
]
|
|
215
|
+
.filter(Boolean)
|
|
216
|
+
.join(" when ");
|
|
217
|
+
const fn = () => value(...args);
|
|
218
|
+
return (0, promises_1.runAsPromise)(fn)
|
|
219
|
+
.catch((0, errors_1.rethrowError)(errMessage))
|
|
220
|
+
.catch((err) => {
|
|
221
|
+
this.log("error", err);
|
|
222
|
+
throw err;
|
|
223
|
+
});
|
|
224
|
+
} });
|
|
225
|
+
}, {});
|
|
226
|
+
this.env =
|
|
227
|
+
(_b = (await ((_a = actions.env) === null || _a === void 0 ? void 0 : _a.call(actions, "starting to handle request")))) !== null && _b !== void 0 ? _b : (0, env_1.allProcessEnv)();
|
|
228
|
+
const getInngestHeaders = () => (0, env_1.inngestHeaders)({
|
|
229
|
+
env: this.env,
|
|
278
230
|
framework: this.frameworkName,
|
|
279
231
|
client: this.client,
|
|
280
232
|
extras: {
|
|
281
233
|
"Server-Timing": timer.getHeader(),
|
|
282
234
|
},
|
|
283
235
|
});
|
|
284
|
-
const actionRes = timer.wrap("action", () => this.handleAction(actions, timer));
|
|
236
|
+
const actionRes = timer.wrap("action", () => this.handleAction(actions, timer, getInngestHeaders));
|
|
285
237
|
/**
|
|
286
238
|
* Prepares an action response by merging returned data to provide
|
|
287
239
|
* trailing information such as `Server-Timing` headers.
|
|
@@ -289,34 +241,43 @@ class InngestCommHandler {
|
|
|
289
241
|
* It should always prioritize the headers returned by the action, as
|
|
290
242
|
* they may contain important information such as `Content-Type`.
|
|
291
243
|
*/
|
|
292
|
-
const prepareActionRes = (res) =>
|
|
244
|
+
const prepareActionRes = (res) => {
|
|
245
|
+
var _a;
|
|
246
|
+
return (Object.assign(Object.assign({}, res), { headers: Object.assign(Object.assign(Object.assign({}, getInngestHeaders()), res.headers), (res.version === null
|
|
247
|
+
? {}
|
|
248
|
+
: {
|
|
249
|
+
[consts_1.headerKeys.RequestVersion]: ((_a = res.version) !== null && _a !== void 0 ? _a : InngestExecution_1.PREFERRED_EXECUTION_VERSION).toString(),
|
|
250
|
+
})) }));
|
|
251
|
+
};
|
|
293
252
|
const wantToStream = this.streaming === "force" ||
|
|
294
253
|
(this.streaming === "allow" &&
|
|
295
|
-
(0, env_1.platformSupportsStreaming)(this.frameworkName,
|
|
296
|
-
if (wantToStream &&
|
|
297
|
-
const
|
|
298
|
-
if (
|
|
254
|
+
(0, env_1.platformSupportsStreaming)(this.frameworkName, this.env));
|
|
255
|
+
if (wantToStream && actions.transformStreamingResponse) {
|
|
256
|
+
const method = await actions.method("starting streaming response");
|
|
257
|
+
if (method === "POST") {
|
|
299
258
|
const { stream, finalize } = await (0, stream_1.createStream)();
|
|
300
259
|
/**
|
|
301
260
|
* Errors are handled by `handleAction` here to ensure that an
|
|
302
261
|
* appropriate response is always given.
|
|
303
262
|
*/
|
|
304
|
-
void actionRes.then((res) =>
|
|
263
|
+
void actionRes.then((res) => {
|
|
264
|
+
return finalize(prepareActionRes(res));
|
|
265
|
+
});
|
|
305
266
|
return timer.wrap("res", () => {
|
|
306
267
|
var _a;
|
|
307
|
-
|
|
308
|
-
return (_a = this.streamTransformRes) === null || _a === void 0 ? void 0 : _a.call(this, {
|
|
268
|
+
return (_a = actions.transformStreamingResponse) === null || _a === void 0 ? void 0 : _a.call(actions, "starting streaming response", {
|
|
309
269
|
status: 201,
|
|
310
|
-
headers:
|
|
270
|
+
headers: getInngestHeaders(),
|
|
311
271
|
body: stream,
|
|
312
|
-
|
|
272
|
+
version: null,
|
|
273
|
+
});
|
|
313
274
|
});
|
|
314
275
|
}
|
|
315
276
|
}
|
|
316
277
|
return timer.wrap("res", async () => {
|
|
317
|
-
return actionRes.then((
|
|
278
|
+
return actionRes.then(prepareActionRes).then((actionRes) => {
|
|
318
279
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
319
|
-
return
|
|
280
|
+
return actions.transformResponse("sending back response", actionRes);
|
|
320
281
|
});
|
|
321
282
|
});
|
|
322
283
|
};
|
|
@@ -332,58 +293,111 @@ class InngestCommHandler {
|
|
|
332
293
|
* will decide whether the UI should be visible based on the payload it has
|
|
333
294
|
* found (e.g. env vars, options, etc).
|
|
334
295
|
*/
|
|
335
|
-
async handleAction(actions, timer) {
|
|
296
|
+
async handleAction(actions, timer, getInngestHeaders) {
|
|
336
297
|
var _a, _b, _c;
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
env: env,
|
|
340
|
-
framework: this.frameworkName,
|
|
341
|
-
client: this.client,
|
|
342
|
-
extras: {
|
|
343
|
-
"Server-Timing": timer.getHeader(),
|
|
344
|
-
},
|
|
345
|
-
});
|
|
346
|
-
this._isProd = (_b = actions.isProduction) !== null && _b !== void 0 ? _b : (0, env_1.isProd)(env);
|
|
298
|
+
this._isProd =
|
|
299
|
+
(_b = (await ((_a = actions.isProduction) === null || _a === void 0 ? void 0 : _a.call(actions, "starting to handle request")))) !== null && _b !== void 0 ? _b : (0, env_1.isProd)(this.env);
|
|
347
300
|
/**
|
|
348
301
|
* If we've been explicitly passed an Inngest dev sever URL, assume that
|
|
349
302
|
* we shouldn't skip the dev server.
|
|
350
303
|
*/
|
|
351
|
-
this._skipDevServer = (0, env_1.devServerHost)(env)
|
|
304
|
+
this._skipDevServer = (0, env_1.devServerHost)(this.env)
|
|
352
305
|
? false
|
|
353
|
-
: (_c = this._isProd) !== null && _c !== void 0 ? _c : (0, env_1.skipDevServer)(env);
|
|
306
|
+
: (_c = this._isProd) !== null && _c !== void 0 ? _c : (0, env_1.skipDevServer)(this.env);
|
|
307
|
+
this.upsertKeysFromEnv();
|
|
354
308
|
try {
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
};
|
|
309
|
+
const url = await actions.url("starting to handle request");
|
|
310
|
+
const method = await actions.method("starting to handle request");
|
|
311
|
+
const getQuerystring = async (reason, key) => {
|
|
312
|
+
var _a;
|
|
313
|
+
const ret = (await ((_a = actions.queryString) === null || _a === void 0 ? void 0 : _a.call(actions, reason, key, url))) ||
|
|
314
|
+
url.searchParams.get(key) ||
|
|
315
|
+
undefined;
|
|
316
|
+
return ret;
|
|
317
|
+
};
|
|
318
|
+
if (method === "POST") {
|
|
319
|
+
const signature = await actions.headers("checking signature for run request", consts_1.headerKeys.Signature);
|
|
320
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
321
|
+
const body = await actions.body("processing run request");
|
|
322
|
+
this.validateSignature(signature !== null && signature !== void 0 ? signature : undefined, body);
|
|
323
|
+
const fnId = await getQuerystring("processing run request", consts_1.queryKeys.FnId);
|
|
324
|
+
if (!fnId) {
|
|
325
|
+
// TODO PrettyError
|
|
326
|
+
throw new Error("No function ID found in request");
|
|
374
327
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
328
|
+
const stepId = (await getQuerystring("processing run request", consts_1.queryKeys.StepId)) ||
|
|
329
|
+
null;
|
|
330
|
+
const { version, result } = this.runStep(fnId, stepId, body, timer);
|
|
331
|
+
const stepOutput = await result;
|
|
332
|
+
/**
|
|
333
|
+
* Functions can return `undefined`, but we'll always convert this to
|
|
334
|
+
* `null`, as this is appropriately serializable by JSON.
|
|
335
|
+
*/
|
|
336
|
+
const opDataUndefinedToNull = (op) => {
|
|
337
|
+
const opData = zod_1.z.object({ data: zod_1.z.any() }).safeParse(op.data);
|
|
338
|
+
if (opData.success) {
|
|
339
|
+
op.data.data = (0, functions_1.undefinedToNull)(opData.data.data);
|
|
340
|
+
}
|
|
341
|
+
return op;
|
|
342
|
+
};
|
|
343
|
+
const resultHandlers = {
|
|
344
|
+
"function-rejected": (result) => {
|
|
345
|
+
return {
|
|
346
|
+
status: result.retriable ? 500 : 400,
|
|
347
|
+
headers: Object.assign({ "Content-Type": "application/json", [consts_1.headerKeys.NoRetry]: result.retriable ? "false" : "true" }, (typeof result.retriable === "string"
|
|
348
|
+
? { [consts_1.headerKeys.RetryAfter]: result.retriable }
|
|
349
|
+
: {})),
|
|
350
|
+
body: (0, strings_1.stringify)((0, functions_1.undefinedToNull)(result.error)),
|
|
351
|
+
version,
|
|
352
|
+
};
|
|
353
|
+
},
|
|
354
|
+
"function-resolved": (result) => {
|
|
355
|
+
return {
|
|
356
|
+
status: 200,
|
|
357
|
+
headers: {
|
|
358
|
+
"Content-Type": "application/json",
|
|
359
|
+
},
|
|
360
|
+
body: (0, strings_1.stringify)((0, functions_1.undefinedToNull)(result.data)),
|
|
361
|
+
version,
|
|
362
|
+
};
|
|
363
|
+
},
|
|
364
|
+
"step-not-found": (result) => {
|
|
365
|
+
return {
|
|
366
|
+
status: 500,
|
|
367
|
+
headers: {
|
|
368
|
+
"Content-Type": "application/json",
|
|
369
|
+
[consts_1.headerKeys.NoRetry]: "false",
|
|
370
|
+
},
|
|
371
|
+
body: (0, strings_1.stringify)({
|
|
372
|
+
error: `Could not find step "${result.step.id}" to run; timed out`,
|
|
373
|
+
}),
|
|
374
|
+
version,
|
|
375
|
+
};
|
|
376
|
+
},
|
|
377
|
+
"step-ran": (result) => {
|
|
378
|
+
const step = opDataUndefinedToNull(result.step);
|
|
379
|
+
return {
|
|
380
|
+
status: 206,
|
|
381
|
+
headers: { "Content-Type": "application/json" },
|
|
382
|
+
body: (0, strings_1.stringify)([step]),
|
|
383
|
+
version,
|
|
384
|
+
};
|
|
385
|
+
},
|
|
386
|
+
"steps-found": (result) => {
|
|
387
|
+
const steps = result.steps.map(opDataUndefinedToNull);
|
|
388
|
+
return {
|
|
389
|
+
status: 206,
|
|
390
|
+
headers: { "Content-Type": "application/json" },
|
|
391
|
+
body: (0, strings_1.stringify)(steps),
|
|
392
|
+
version,
|
|
393
|
+
};
|
|
380
394
|
},
|
|
381
395
|
};
|
|
396
|
+
const handler = resultHandlers[stepOutput.type];
|
|
397
|
+
return await handler(stepOutput);
|
|
382
398
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
this.upsertKeysFromEnv(env);
|
|
386
|
-
const registerBody = this.registerBody(this.reqUrl(actions.url));
|
|
399
|
+
if (method === "GET") {
|
|
400
|
+
const registerBody = this.registerBody(this.reqUrl(url));
|
|
387
401
|
const introspection = {
|
|
388
402
|
message: "Inngest endpoint configured correctly.",
|
|
389
403
|
hasEventKey: Boolean(this.client["eventKey"]),
|
|
@@ -396,18 +410,19 @@ class InngestCommHandler {
|
|
|
396
410
|
headers: {
|
|
397
411
|
"Content-Type": "application/json",
|
|
398
412
|
},
|
|
413
|
+
version: undefined,
|
|
399
414
|
};
|
|
400
415
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
this.
|
|
404
|
-
const { status, message, modified } = await this.register(this.reqUrl(actions.url), (0, strings_1.stringifyUnknown)(env[consts_1.envKeys.DevServerUrl]), registerRes.deployId, getHeaders);
|
|
416
|
+
if (method === "PUT") {
|
|
417
|
+
const deployId = await getQuerystring("processing deployment request", consts_1.queryKeys.DeployId);
|
|
418
|
+
const { status, message, modified } = await this.register(this.reqUrl(url), deployId, getInngestHeaders);
|
|
405
419
|
return {
|
|
406
420
|
status,
|
|
407
421
|
body: (0, strings_1.stringify)({ message, modified }),
|
|
408
422
|
headers: {
|
|
409
423
|
"Content-Type": "application/json",
|
|
410
424
|
},
|
|
425
|
+
version: undefined,
|
|
411
426
|
};
|
|
412
427
|
}
|
|
413
428
|
}
|
|
@@ -418,6 +433,7 @@ class InngestCommHandler {
|
|
|
418
433
|
headers: {
|
|
419
434
|
"Content-Type": "application/json",
|
|
420
435
|
},
|
|
436
|
+
version: undefined,
|
|
421
437
|
};
|
|
422
438
|
}
|
|
423
439
|
return {
|
|
@@ -428,104 +444,83 @@ class InngestCommHandler {
|
|
|
428
444
|
skipDevServer: this._skipDevServer,
|
|
429
445
|
}),
|
|
430
446
|
headers: {},
|
|
447
|
+
version: undefined,
|
|
431
448
|
};
|
|
432
449
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
// TODO PrettyError
|
|
439
|
-
throw new Error(`Could not find function with ID "${functionId}"`);
|
|
440
|
-
}
|
|
441
|
-
const fndata = await (0, functions_1.parseFnData)(data, this.client["inngestApi"]);
|
|
442
|
-
if (!fndata.ok) {
|
|
443
|
-
throw new Error(fndata.error);
|
|
444
|
-
}
|
|
445
|
-
const { event, events, steps, ctx } = fndata.value;
|
|
446
|
-
/**
|
|
447
|
-
* TODO When the executor does support per-step errors, this map will need
|
|
448
|
-
* to adjust to ensure we're not double-stacking the op inside `data`.
|
|
449
|
-
*/
|
|
450
|
-
const opStack = (_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.stack) === null || _a === void 0 ? void 0 : _a.stack.slice(0, ctx.stack.current).map((opId) => {
|
|
451
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
452
|
-
const step = steps === null || steps === void 0 ? void 0 : steps[opId];
|
|
453
|
-
if (typeof step === "undefined") {
|
|
454
|
-
// TODO PrettyError
|
|
455
|
-
throw new Error(`Could not find step with ID "${opId}"`);
|
|
456
|
-
}
|
|
457
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
458
|
-
return { id: opId, data: step };
|
|
459
|
-
})) !== null && _b !== void 0 ? _b : [];
|
|
460
|
-
const ret = await fn.fn["runFn"]({ event, events, runId: ctx === null || ctx === void 0 ? void 0 : ctx.run_id, attempt: ctx === null || ctx === void 0 ? void 0 : ctx.attempt }, opStack,
|
|
461
|
-
/**
|
|
462
|
-
* TODO The executor is sending `"step"` as the step ID when it is not
|
|
463
|
-
* wanting to run a specific step. This is not needed and we should
|
|
464
|
-
* remove this on the executor side.
|
|
465
|
-
*/
|
|
466
|
-
stepId === "step" ? null : stepId || null, timer, fn.onFailure);
|
|
467
|
-
if (ret[0] === "complete") {
|
|
468
|
-
return {
|
|
469
|
-
status: 200,
|
|
470
|
-
body: ret[1],
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* If the function has run user code and is intending to return an error,
|
|
475
|
-
* interrupt this flow and instead throw a 500 to Inngest.
|
|
476
|
-
*
|
|
477
|
-
* The executor doesn't yet support per-step errors, so returning an
|
|
478
|
-
* `error` key here would cause the executor to misunderstand what is
|
|
479
|
-
* happening.
|
|
480
|
-
*
|
|
481
|
-
* TODO When the executor does support per-step errors, we can remove this
|
|
482
|
-
* comment and check and functionality should resume as normal.
|
|
483
|
-
*/
|
|
484
|
-
if (ret[0] === "run" && ret[1].error) {
|
|
485
|
-
/**
|
|
486
|
-
* We throw the `data` here instead of the `error` because we expect
|
|
487
|
-
* `data` to be a prepared version of the error which may have been
|
|
488
|
-
* altered by middleware, whereas `error` is the initial triggering
|
|
489
|
-
* error.
|
|
490
|
-
*/
|
|
491
|
-
throw new errors_1.OutgoingResultError({
|
|
492
|
-
data: ret[1].data,
|
|
493
|
-
error: ret[1].error,
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
return {
|
|
497
|
-
status: 206,
|
|
498
|
-
body: Array.isArray(ret[1]) ? ret[1] : [ret[1]],
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
catch (unserializedErr) {
|
|
502
|
-
/**
|
|
503
|
-
* Always serialize the error before sending it back to Inngest. Errors,
|
|
504
|
-
* by default, do not niceley serialize to JSON, so we use the a package
|
|
505
|
-
* to do this.
|
|
506
|
-
*
|
|
507
|
-
* See {@link https://www.npmjs.com/package/serialize-error}
|
|
508
|
-
*/
|
|
509
|
-
const isOutgoingOpError = unserializedErr instanceof errors_1.OutgoingResultError;
|
|
510
|
-
const error = (0, strings_1.stringify)((0, errors_1.serializeError)(isOutgoingOpError ? unserializedErr.result.data : unserializedErr));
|
|
511
|
-
const isNonRetriableError = isOutgoingOpError
|
|
512
|
-
? unserializedErr.result.error instanceof NonRetriableError_1.NonRetriableError
|
|
513
|
-
: unserializedErr instanceof NonRetriableError_1.NonRetriableError;
|
|
514
|
-
/**
|
|
515
|
-
* If we've caught a non-retriable error, we'll return a 400 to Inngest
|
|
516
|
-
* to indicate that the error is not transient and should not be retried.
|
|
517
|
-
*
|
|
518
|
-
* The errors caught here are caught from the main function as well as
|
|
519
|
-
* inside individual steps, so this safely catches all areas.
|
|
520
|
-
*/
|
|
521
|
-
return {
|
|
522
|
-
status: isNonRetriableError ? 400 : 500,
|
|
523
|
-
error,
|
|
524
|
-
};
|
|
450
|
+
runStep(functionId, stepId, data, timer) {
|
|
451
|
+
const fn = this.fns[functionId];
|
|
452
|
+
if (!fn) {
|
|
453
|
+
// TODO PrettyError
|
|
454
|
+
throw new Error(`Could not find function with ID "${functionId}"`);
|
|
525
455
|
}
|
|
456
|
+
const immediateFnData = (0, functions_1.parseFnData)(data);
|
|
457
|
+
const { version } = immediateFnData;
|
|
458
|
+
const result = (0, promises_1.runAsPromise)(async () => {
|
|
459
|
+
const anyFnData = await (0, functions_1.fetchAllFnData)(immediateFnData, this.client["inngestApi"]);
|
|
460
|
+
if (!anyFnData.ok) {
|
|
461
|
+
throw new Error(anyFnData.error);
|
|
462
|
+
}
|
|
463
|
+
const executionStarters = ((s) => s)({
|
|
464
|
+
[InngestExecution_1.ExecutionVersion.V0]: ({ event, events, steps, ctx, version }) => {
|
|
465
|
+
var _a, _b, _c;
|
|
466
|
+
const stepState = Object.entries(steps !== null && steps !== void 0 ? steps : {}).reduce((acc, [id, data]) => {
|
|
467
|
+
return Object.assign(Object.assign({}, acc), {
|
|
468
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
469
|
+
[id]: { id, data } });
|
|
470
|
+
}, {});
|
|
471
|
+
return {
|
|
472
|
+
version,
|
|
473
|
+
partialOptions: {
|
|
474
|
+
runId: (ctx === null || ctx === void 0 ? void 0 : ctx.run_id) || "",
|
|
475
|
+
data: {
|
|
476
|
+
event: event,
|
|
477
|
+
events: events,
|
|
478
|
+
runId: (ctx === null || ctx === void 0 ? void 0 : ctx.run_id) || "",
|
|
479
|
+
attempt: (_a = ctx === null || ctx === void 0 ? void 0 : ctx.attempt) !== null && _a !== void 0 ? _a : 0,
|
|
480
|
+
},
|
|
481
|
+
stepState,
|
|
482
|
+
requestedRunStep: stepId === "step" ? undefined : stepId || undefined,
|
|
483
|
+
timer,
|
|
484
|
+
isFailureHandler: fn.onFailure,
|
|
485
|
+
stepCompletionOrder: (_c = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.stack) === null || _b === void 0 ? void 0 : _b.stack) !== null && _c !== void 0 ? _c : [],
|
|
486
|
+
},
|
|
487
|
+
};
|
|
488
|
+
},
|
|
489
|
+
[InngestExecution_1.ExecutionVersion.V1]: ({ event, events, steps, ctx, version }) => {
|
|
490
|
+
var _a, _b, _c;
|
|
491
|
+
const stepState = Object.entries(steps !== null && steps !== void 0 ? steps : {}).reduce((acc, [id, result]) => {
|
|
492
|
+
return Object.assign(Object.assign({}, acc), { [id]: result.type === "data"
|
|
493
|
+
? // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
494
|
+
{ id, data: result.data }
|
|
495
|
+
: { id, error: result.error } });
|
|
496
|
+
}, {});
|
|
497
|
+
return {
|
|
498
|
+
version,
|
|
499
|
+
partialOptions: {
|
|
500
|
+
runId: (ctx === null || ctx === void 0 ? void 0 : ctx.run_id) || "",
|
|
501
|
+
data: {
|
|
502
|
+
event: event,
|
|
503
|
+
events: events,
|
|
504
|
+
runId: (ctx === null || ctx === void 0 ? void 0 : ctx.run_id) || "",
|
|
505
|
+
attempt: (_a = ctx === null || ctx === void 0 ? void 0 : ctx.attempt) !== null && _a !== void 0 ? _a : 0,
|
|
506
|
+
},
|
|
507
|
+
stepState,
|
|
508
|
+
requestedRunStep: stepId === "step" ? undefined : stepId || undefined,
|
|
509
|
+
timer,
|
|
510
|
+
isFailureHandler: fn.onFailure,
|
|
511
|
+
disableImmediateExecution: ctx === null || ctx === void 0 ? void 0 : ctx.disable_immediate_execution,
|
|
512
|
+
stepCompletionOrder: (_c = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.stack) === null || _b === void 0 ? void 0 : _b.stack) !== null && _c !== void 0 ? _c : [],
|
|
513
|
+
},
|
|
514
|
+
};
|
|
515
|
+
},
|
|
516
|
+
});
|
|
517
|
+
const executionOptions = await executionStarters[anyFnData.value.version](anyFnData.value);
|
|
518
|
+
return fn.fn["createExecution"](executionOptions).start();
|
|
519
|
+
});
|
|
520
|
+
return { version, result };
|
|
526
521
|
}
|
|
527
522
|
configs(url) {
|
|
528
|
-
return Object.values(this.rawFns).reduce((acc, fn) => [...acc, ...fn["getConfig"](url, this.
|
|
523
|
+
return Object.values(this.rawFns).reduce((acc, fn) => [...acc, ...fn["getConfig"](url, this.id)], []);
|
|
529
524
|
}
|
|
530
525
|
/**
|
|
531
526
|
* Return an Inngest serve endpoint URL given a potential `path` and `host`.
|
|
@@ -535,14 +530,14 @@ class InngestCommHandler {
|
|
|
535
530
|
*/
|
|
536
531
|
reqUrl(url) {
|
|
537
532
|
let ret = new URL(url);
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
if (
|
|
541
|
-
ret
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
533
|
+
const serveHost = this.serveHost || this.env[consts_1.envKeys.InngestServeHost];
|
|
534
|
+
const servePath = this.servePath || this.env[consts_1.envKeys.InngestServePath];
|
|
535
|
+
if (servePath) {
|
|
536
|
+
ret.pathname = servePath;
|
|
537
|
+
}
|
|
538
|
+
if (serveHost) {
|
|
539
|
+
ret = new URL(ret.pathname + ret.search, serveHost);
|
|
540
|
+
}
|
|
546
541
|
return ret;
|
|
547
542
|
}
|
|
548
543
|
registerBody(url) {
|
|
@@ -550,7 +545,7 @@ class InngestCommHandler {
|
|
|
550
545
|
url: url.href,
|
|
551
546
|
deployType: "ping",
|
|
552
547
|
framework: this.frameworkName,
|
|
553
|
-
appName: this.
|
|
548
|
+
appName: this.id,
|
|
554
549
|
functions: this.configs(url),
|
|
555
550
|
sdk: `js:v${version_1.version}`,
|
|
556
551
|
v: "0.1",
|
|
@@ -559,19 +554,20 @@ class InngestCommHandler {
|
|
|
559
554
|
body.hash = (0, hash_js_1.sha256)().update((0, canonicalize_1.default)(body)).digest("hex");
|
|
560
555
|
return body;
|
|
561
556
|
}
|
|
562
|
-
async register(url,
|
|
557
|
+
async register(url, deployId, getHeaders) {
|
|
563
558
|
const body = this.registerBody(url);
|
|
564
559
|
let res;
|
|
565
560
|
// Whenever we register, we check to see if the dev server is up. This
|
|
566
561
|
// is a noop and returns false in production.
|
|
567
562
|
let registerURL = this.inngestRegisterUrl;
|
|
568
563
|
if (!this._skipDevServer) {
|
|
569
|
-
const
|
|
564
|
+
const host = (0, env_1.devServerHost)(this.env);
|
|
565
|
+
const hasDevServer = await (0, devserver_1.devServerAvailable)(host, this.fetch);
|
|
570
566
|
if (hasDevServer) {
|
|
571
|
-
registerURL = (0, devserver_1.devServerUrl)(
|
|
567
|
+
registerURL = (0, devserver_1.devServerUrl)(host, "/fn/register");
|
|
572
568
|
}
|
|
573
569
|
}
|
|
574
|
-
if (deployId) {
|
|
570
|
+
if (deployId && deployId !== "undefined") {
|
|
575
571
|
registerURL.searchParams.set(consts_1.queryKeys.DeployId, deployId);
|
|
576
572
|
}
|
|
577
573
|
try {
|
|
@@ -618,12 +614,22 @@ class InngestCommHandler {
|
|
|
618
614
|
* situations where environment variables are passed directly to handlers or
|
|
619
615
|
* are otherwise difficult to access during initialization.
|
|
620
616
|
*/
|
|
621
|
-
upsertKeysFromEnv(
|
|
622
|
-
if (
|
|
623
|
-
this.signingKey
|
|
617
|
+
upsertKeysFromEnv() {
|
|
618
|
+
if (this.env[consts_1.envKeys.InngestSigningKey]) {
|
|
619
|
+
if (!this.signingKey) {
|
|
620
|
+
this.signingKey = String(this.env[consts_1.envKeys.InngestSigningKey]);
|
|
621
|
+
}
|
|
622
|
+
this.client["inngestApi"].setSigningKey(this.signingKey);
|
|
623
|
+
}
|
|
624
|
+
if (!this.client["eventKey"] && this.env[consts_1.envKeys.InngestEventKey]) {
|
|
625
|
+
this.client.setEventKey(String(this.env[consts_1.envKeys.InngestEventKey]));
|
|
626
|
+
}
|
|
627
|
+
// v2 -> v3 migration warnings
|
|
628
|
+
if (this.env[consts_1.envKeys.InngestDevServerUrl]) {
|
|
629
|
+
this.log("warn", `Use of ${consts_1.envKeys.InngestDevServerUrl} has been deprecated in v3; please use ${consts_1.envKeys.InngestBaseUrl} instead. See https://www.inngest.com/docs/sdk/migration`);
|
|
624
630
|
}
|
|
625
|
-
if (
|
|
626
|
-
this.
|
|
631
|
+
if (this.env[consts_1.envKeys.InngestApiBaseUrl]) {
|
|
632
|
+
this.log("warn", `Use of ${consts_1.envKeys.InngestApiBaseUrl} has been deprecated in v3; please use ${consts_1.envKeys.InngestBaseUrl} instead. See https://www.inngest.com/docs/sdk/migration`);
|
|
627
633
|
}
|
|
628
634
|
}
|
|
629
635
|
validateSignature(sig, body) {
|
|
@@ -639,7 +645,7 @@ class InngestCommHandler {
|
|
|
639
645
|
// If we're here, we're in production; lack of a signing key is an error.
|
|
640
646
|
if (!this.signingKey) {
|
|
641
647
|
// TODO PrettyError
|
|
642
|
-
throw new Error(`No signing key found in client options or ${consts_1.envKeys.
|
|
648
|
+
throw new Error(`No signing key found in client options or ${consts_1.envKeys.InngestSigningKey} env var. Find your keys at https://app.inngest.com/secrets`);
|
|
643
649
|
}
|
|
644
650
|
// If we're here, we're in production; lack of a req signature is an error.
|
|
645
651
|
if (!sig) {
|
|
@@ -677,10 +683,10 @@ class InngestCommHandler {
|
|
|
677
683
|
const currentLevel = logLevels.indexOf(level);
|
|
678
684
|
if (currentLevel >= logLevelSetting) {
|
|
679
685
|
let logger = console.log;
|
|
680
|
-
if (Object.hasOwnProperty.call(console, level)) {
|
|
686
|
+
if (Object.prototype.hasOwnProperty.call(console, level)) {
|
|
681
687
|
logger = console[level];
|
|
682
688
|
}
|
|
683
|
-
logger(
|
|
689
|
+
logger(`${consts_1.logPrefix} ${level} -`, ...args);
|
|
684
690
|
}
|
|
685
691
|
}
|
|
686
692
|
}
|