inngest 0.8.8 → 0.8.10
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/cloudflare.d.ts +1 -1
- package/cloudflare.d.ts.map +1 -1
- package/cloudflare.js +50 -81
- package/cloudflare.js.map +1 -1
- package/components/Inngest.d.ts.map +1 -1
- package/components/Inngest.js +1 -1
- package/components/Inngest.js.map +1 -1
- package/components/InngestCommHandler.d.ts +380 -0
- package/components/InngestCommHandler.d.ts.map +1 -0
- package/components/InngestCommHandler.js +474 -0
- package/components/InngestCommHandler.js.map +1 -0
- package/components/InngestStepTools.d.ts +5 -3
- package/components/InngestStepTools.d.ts.map +1 -1
- package/components/InngestStepTools.js +17 -5
- package/components/InngestStepTools.js.map +1 -1
- package/components/NonRetriableError.d.ts +26 -0
- package/components/NonRetriableError.d.ts.map +1 -0
- package/components/NonRetriableError.js +21 -0
- package/components/NonRetriableError.js.map +1 -0
- package/deno/fresh.d.ts +9 -0
- package/deno/fresh.d.ts.map +1 -0
- package/deno/fresh.js +55 -0
- package/deno/fresh.js.map +1 -0
- package/digitalocean.d.ts +15 -0
- package/digitalocean.d.ts.map +1 -0
- package/digitalocean.js +72 -0
- package/digitalocean.js.map +1 -0
- package/express.d.ts +2 -122
- package/express.d.ts.map +1 -1
- package/express.js +48 -302
- package/express.js.map +1 -1
- package/helpers/consts.d.ts +2 -1
- package/helpers/consts.d.ts.map +1 -1
- package/helpers/consts.js +1 -0
- package/helpers/consts.js.map +1 -1
- package/helpers/devserver.d.ts +5 -5
- package/helpers/devserver.d.ts.map +1 -1
- package/helpers/devserver.js +1 -1
- package/helpers/env.d.ts +2 -6
- package/helpers/env.d.ts.map +1 -1
- package/helpers/env.js +23 -17
- package/helpers/env.js.map +1 -1
- package/helpers/types.d.ts +13 -9
- package/helpers/types.d.ts.map +1 -1
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -1
- package/index.js +5 -1
- package/index.js.map +1 -1
- package/init.js +2 -1
- package/init.js.map +1 -1
- package/landing.d.ts +1 -1
- package/landing.d.ts.map +1 -1
- package/landing.js +1 -1
- package/landing.js.map +1 -1
- package/next.d.ts +1 -1
- package/next.d.ts.map +1 -1
- package/next.js +49 -69
- package/next.js.map +1 -1
- package/package.json +11 -9
- package/redwood.d.ts +1 -1
- package/redwood.d.ts.map +1 -1
- package/redwood.js +53 -98
- package/redwood.js.map +1 -1
- package/remix.d.ts +1 -1
- package/remix.d.ts.map +1 -1
- package/remix.js +61 -105
- package/remix.js.map +1 -1
- package/types.d.ts +14 -29
- package/types.d.ts.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InngestCommHandler = void 0;
|
|
4
|
+
const hash_js_1 = require("hash.js");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const consts_1 = require("../helpers/consts");
|
|
7
|
+
const devserver_1 = require("../helpers/devserver");
|
|
8
|
+
const scalar_1 = require("../helpers/scalar");
|
|
9
|
+
const landing_1 = require("../landing");
|
|
10
|
+
const version_1 = require("../version");
|
|
11
|
+
const NonRetriableError_1 = require("./NonRetriableError");
|
|
12
|
+
/**
|
|
13
|
+
* A schema for the response from Inngest when registering.
|
|
14
|
+
*/
|
|
15
|
+
const registerResSchema = zod_1.z.object({
|
|
16
|
+
status: zod_1.z.number().default(200),
|
|
17
|
+
skipped: zod_1.z.boolean().optional().default(false),
|
|
18
|
+
error: zod_1.z.string().default("Successfully registered"),
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* `InngestCommHandler` is a class for handling incoming requests from Inngest (or
|
|
22
|
+
* Inngest's tooling such as the dev server or CLI) and taking appropriate
|
|
23
|
+
* action for any served functions.
|
|
24
|
+
*
|
|
25
|
+
* All handlers (Next.js, RedwoodJS, Remix, Deno Fresh, etc) are created using
|
|
26
|
+
* this class; the exposed `serve` function will - most commonly - create an
|
|
27
|
+
* instance of `InngestCommHandler` and then return `instance.createHandler()`.
|
|
28
|
+
*
|
|
29
|
+
* Two critical parameters required are the `handler` and the `transformRes`
|
|
30
|
+
* function. See individual parameter details for more information, or see the
|
|
31
|
+
* source code for an existing handler, e.g.
|
|
32
|
+
* {@link https://github.com/inngest/inngest-js/blob/main/src/next.ts}
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```
|
|
36
|
+
* // my-custom-handler.ts
|
|
37
|
+
* import { InngestCommHandler, ServeHandler } from "inngest";
|
|
38
|
+
*
|
|
39
|
+
* export const serve: ServeHandler = (nameOrInngest, fns, opts) => {
|
|
40
|
+
* const handler = new InngestCommHandler(
|
|
41
|
+
* "my-custom-handler",
|
|
42
|
+
* nameOrInngest,
|
|
43
|
+
* fns,
|
|
44
|
+
* opts,
|
|
45
|
+
* () => { ... },
|
|
46
|
+
* () => { ... }
|
|
47
|
+
* );
|
|
48
|
+
*
|
|
49
|
+
* return handler.createHandler();
|
|
50
|
+
* };
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
class InngestCommHandler {
|
|
56
|
+
constructor(
|
|
57
|
+
/**
|
|
58
|
+
* The name of the framework this handler is designed for. Should be
|
|
59
|
+
* lowercase, alphanumeric characters inclusive of `-` and `/`.
|
|
60
|
+
*
|
|
61
|
+
* This should never be defined by the user; a {@link ServeHandler} should
|
|
62
|
+
* abstract this.
|
|
63
|
+
*/
|
|
64
|
+
frameworkName,
|
|
65
|
+
/**
|
|
66
|
+
* The name of this serve handler, e.g. `"My App"`. It's recommended that this
|
|
67
|
+
* value represents the overarching app/service that this set of functions is
|
|
68
|
+
* being served from.
|
|
69
|
+
*
|
|
70
|
+
* This can also be an `Inngest` client, in which case the name given when
|
|
71
|
+
* instantiating the client is used. This is useful if you're sending and
|
|
72
|
+
* receiving events from the same service, as you can reuse a single
|
|
73
|
+
* definition of Inngest.
|
|
74
|
+
*/
|
|
75
|
+
appNameOrInngest,
|
|
76
|
+
/**
|
|
77
|
+
* An array of the functions to serve and register with Inngest.
|
|
78
|
+
*/
|
|
79
|
+
functions, { inngestRegisterUrl, fetch, landingPage, signingKey, serveHost, servePath, } = {},
|
|
80
|
+
/**
|
|
81
|
+
* The `handler` is the function your framework requires to handle a
|
|
82
|
+
* request. For example, this is most commonly a function that is given a
|
|
83
|
+
* `Request` and must return a `Response`.
|
|
84
|
+
*
|
|
85
|
+
* The handler must map out any incoming parameters, then return a
|
|
86
|
+
* strictly-typed object to assess what kind of request is being made,
|
|
87
|
+
* collecting any relevant data as we go.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```
|
|
91
|
+
* return {
|
|
92
|
+
* register: () => { ... },
|
|
93
|
+
* run: () => { ... },
|
|
94
|
+
* view: () => { ... }
|
|
95
|
+
* };
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* Every key must be specified and must be a function that either returns
|
|
99
|
+
* a strictly-typed payload or `undefined` if the request is not for that
|
|
100
|
+
* purpose.
|
|
101
|
+
*
|
|
102
|
+
* This gives handlers freedom to choose how their platform of choice will
|
|
103
|
+
* trigger differing actions, whilst also ensuring all required information
|
|
104
|
+
* is given for each request type.
|
|
105
|
+
*
|
|
106
|
+
* See any existing handler for a full example.
|
|
107
|
+
*
|
|
108
|
+
* This should never be defined by the user; a {@link ServeHandler} should
|
|
109
|
+
* abstract this.
|
|
110
|
+
*/
|
|
111
|
+
handler,
|
|
112
|
+
/**
|
|
113
|
+
* The `transformRes` function receives the output of the Inngest SDK and
|
|
114
|
+
* can decide how to package up that information to appropriately return the
|
|
115
|
+
* information to Inngest.
|
|
116
|
+
*
|
|
117
|
+
* Mostly, this is taking the given parameters and returning a new
|
|
118
|
+
* `Response`.
|
|
119
|
+
*
|
|
120
|
+
* The function is passed an {@link ActionResponse} (an object containing a
|
|
121
|
+
* `status` code, a `headers` object, and a stringified `body`), as well as
|
|
122
|
+
* every parameter passed to the given `handler` function. This ensures you
|
|
123
|
+
* can appropriately handle the response, including use of any required
|
|
124
|
+
* parameters such as `res` in Express-/Connect-like frameworks.
|
|
125
|
+
*
|
|
126
|
+
* This should never be defined by the user; a {@link ServeHandler} should
|
|
127
|
+
* abstract this.
|
|
128
|
+
*/
|
|
129
|
+
transformRes) {
|
|
130
|
+
/**
|
|
131
|
+
* A property that can be set to indicate whether or not we believe we are in
|
|
132
|
+
* production mode.
|
|
133
|
+
*
|
|
134
|
+
* Should be set every time a request is received.
|
|
135
|
+
*/
|
|
136
|
+
this._isProd = false;
|
|
137
|
+
/**
|
|
138
|
+
* A private collection of functions that are being served. This map is used
|
|
139
|
+
* to find and register functions when interacting with Inngest Cloud.
|
|
140
|
+
*/
|
|
141
|
+
this.fns = {};
|
|
142
|
+
this.frameworkName = frameworkName;
|
|
143
|
+
this.name =
|
|
144
|
+
typeof appNameOrInngest === "string"
|
|
145
|
+
? appNameOrInngest
|
|
146
|
+
: appNameOrInngest.name;
|
|
147
|
+
this.handler = handler;
|
|
148
|
+
this.transformRes = transformRes;
|
|
149
|
+
this.fns = functions.reduce((acc, fn) => {
|
|
150
|
+
const id = fn.id(this.name);
|
|
151
|
+
if (acc[id]) {
|
|
152
|
+
throw new Error(`Duplicate function ID "${id}"; please change a function's name or provide an explicit ID to avoid conflicts.`);
|
|
153
|
+
}
|
|
154
|
+
return Object.assign(Object.assign({}, acc), { [id]: fn });
|
|
155
|
+
}, {});
|
|
156
|
+
this.inngestRegisterUrl = new URL(inngestRegisterUrl || "https://api.inngest.com/fn/register");
|
|
157
|
+
this.signingKey = signingKey;
|
|
158
|
+
this.showLandingPage = landingPage;
|
|
159
|
+
this.serveHost = serveHost;
|
|
160
|
+
this.servePath = servePath;
|
|
161
|
+
this.headers = {
|
|
162
|
+
"Content-Type": "application/json",
|
|
163
|
+
"User-Agent": `inngest-js:v${version_1.version} (${this.frameworkName})`,
|
|
164
|
+
};
|
|
165
|
+
this.fetch =
|
|
166
|
+
fetch ||
|
|
167
|
+
(typeof appNameOrInngest === "string"
|
|
168
|
+
? undefined
|
|
169
|
+
: appNameOrInngest["fetch"]) ||
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
171
|
+
require("cross-fetch");
|
|
172
|
+
}
|
|
173
|
+
// hashedSigningKey creates a sha256 checksum of the signing key with the
|
|
174
|
+
// same signing key prefix.
|
|
175
|
+
get hashedSigningKey() {
|
|
176
|
+
var _a;
|
|
177
|
+
if (!this.signingKey) {
|
|
178
|
+
return "";
|
|
179
|
+
}
|
|
180
|
+
const prefix = ((_a = this.signingKey.match(/^signkey-(test|prod)-/)) === null || _a === void 0 ? void 0 : _a.shift()) || "";
|
|
181
|
+
const key = this.signingKey.replace(/^signkey-(test|prod)-/, "");
|
|
182
|
+
// Decode the key from its hex representation into a bytestream
|
|
183
|
+
return `${prefix}${(0, hash_js_1.sha256)().update(key, "hex").digest("hex")}`;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* `createHandler` should be used to return a type-equivalent version of the
|
|
187
|
+
* `handler` specified during instantiation.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```
|
|
191
|
+
* // my-custom-handler.ts
|
|
192
|
+
* import { InngestCommHandler, ServeHandler } from "inngest";
|
|
193
|
+
*
|
|
194
|
+
* export const serve: ServeHandler = (nameOrInngest, fns, opts) => {
|
|
195
|
+
* const handler = new InngestCommHandler(
|
|
196
|
+
* "my-custom-handler",
|
|
197
|
+
* nameOrInngest,
|
|
198
|
+
* fns,
|
|
199
|
+
* opts,
|
|
200
|
+
* () => { ... },
|
|
201
|
+
* () => { ... }
|
|
202
|
+
* );
|
|
203
|
+
*
|
|
204
|
+
* return handler.createHandler();
|
|
205
|
+
* };
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
createHandler() {
|
|
209
|
+
return async (...args) => {
|
|
210
|
+
/**
|
|
211
|
+
* We purposefully `await` the handler, as it could be either sync or
|
|
212
|
+
* async.
|
|
213
|
+
*/
|
|
214
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
215
|
+
const actions = await this.handler(...args);
|
|
216
|
+
const actionRes = await this.handleAction(actions);
|
|
217
|
+
return this.transformRes(actionRes, ...args);
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Given a set of functions to check if an action is available from the
|
|
222
|
+
* instance's handler, enact any action that is found.
|
|
223
|
+
*
|
|
224
|
+
* This method can fetch varying payloads of data, but ultimately is the place
|
|
225
|
+
* where _decisions_ are made regarding functionality.
|
|
226
|
+
*
|
|
227
|
+
* For example, if we find that we should be viewing the UI, this function
|
|
228
|
+
* will decide whether the UI should be visible based on the payload it has
|
|
229
|
+
* found (e.g. env vars, options, etc).
|
|
230
|
+
*/
|
|
231
|
+
async handleAction(actions) {
|
|
232
|
+
const headers = { "x-inngest-sdk": this.sdkHeader.join("") };
|
|
233
|
+
try {
|
|
234
|
+
const runRes = await actions.run();
|
|
235
|
+
if (runRes) {
|
|
236
|
+
this.upsertSigningKeyFromEnv(runRes.env);
|
|
237
|
+
const stepRes = await this.runStep(runRes.fnId, "step", runRes.data);
|
|
238
|
+
if (stepRes.status === 500 || stepRes.status === 400) {
|
|
239
|
+
return {
|
|
240
|
+
status: stepRes.status,
|
|
241
|
+
body: stepRes.error || "",
|
|
242
|
+
headers: Object.assign(Object.assign({}, headers), { "Content-Type": "application/json" }),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
status: stepRes.status,
|
|
247
|
+
body: JSON.stringify(stepRes.body),
|
|
248
|
+
headers: Object.assign(Object.assign({}, headers), { "Content-Type": "application/json" }),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
const viewRes = await actions.view();
|
|
252
|
+
if (viewRes) {
|
|
253
|
+
this.upsertSigningKeyFromEnv(viewRes.env);
|
|
254
|
+
const showLandingPage = this.shouldShowLandingPage(viewRes.env[consts_1.envKeys.LandingPage]);
|
|
255
|
+
if (this._isProd || !showLandingPage) {
|
|
256
|
+
return {
|
|
257
|
+
status: 405,
|
|
258
|
+
body: "",
|
|
259
|
+
headers,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
if (viewRes.isIntrospection) {
|
|
263
|
+
const introspection = Object.assign(Object.assign({}, this.registerBody(this.reqUrl(viewRes.url))), { devServerURL: (0, devserver_1.devServerUrl)(viewRes.env[consts_1.envKeys.DevServerUrl]).href, hasSigningKey: Boolean(this.signingKey) });
|
|
264
|
+
return {
|
|
265
|
+
status: 200,
|
|
266
|
+
body: JSON.stringify(introspection),
|
|
267
|
+
headers: Object.assign(Object.assign({}, headers), { "Content-Type": "application/json" }),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
status: 200,
|
|
272
|
+
body: landing_1.landing,
|
|
273
|
+
headers: Object.assign(Object.assign({}, headers), { "Content-Type": "text/html; charset=utf-8" }),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const registerRes = await actions.register();
|
|
277
|
+
if (registerRes) {
|
|
278
|
+
this.upsertSigningKeyFromEnv(registerRes.env);
|
|
279
|
+
const { status, message } = await this.register(this.reqUrl(registerRes.url), registerRes.env[consts_1.envKeys.DevServerUrl], registerRes.deployId);
|
|
280
|
+
return {
|
|
281
|
+
status,
|
|
282
|
+
body: JSON.stringify({ message }),
|
|
283
|
+
headers: Object.assign(Object.assign({}, headers), { "Content-Type": "application/json" }),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (err) {
|
|
288
|
+
return {
|
|
289
|
+
status: 500,
|
|
290
|
+
body: JSON.stringify(err),
|
|
291
|
+
headers: Object.assign(Object.assign({}, headers), { "Content-Type": "application/json" }),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
status: 405,
|
|
296
|
+
body: "",
|
|
297
|
+
headers,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
async runStep(functionId, stepId, data) {
|
|
301
|
+
try {
|
|
302
|
+
const fn = this.fns[functionId];
|
|
303
|
+
if (!fn) {
|
|
304
|
+
throw new Error(`Could not find function with ID "${functionId}"`);
|
|
305
|
+
}
|
|
306
|
+
const { event, steps } = zod_1.z
|
|
307
|
+
.object({
|
|
308
|
+
event: zod_1.z.object({}).passthrough(),
|
|
309
|
+
steps: zod_1.z.object({}).passthrough().optional().nullable(),
|
|
310
|
+
})
|
|
311
|
+
.parse(data);
|
|
312
|
+
const ret = await fn["runFn"]({ event }, steps || {});
|
|
313
|
+
const isOp = ret[0];
|
|
314
|
+
if (isOp) {
|
|
315
|
+
return {
|
|
316
|
+
status: 206,
|
|
317
|
+
body: ret[1],
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
status: 200,
|
|
322
|
+
body: ret[1],
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
catch (err) {
|
|
326
|
+
/**
|
|
327
|
+
* If we've caught a non-retriable error, we'll return a 400 to Inngest
|
|
328
|
+
* to indicate that the error is not transient and should not be retried.
|
|
329
|
+
*
|
|
330
|
+
* The errors caught here are caught from the main function as well as
|
|
331
|
+
* inside individual steps, so this safely catches all areas.
|
|
332
|
+
*/
|
|
333
|
+
if (err instanceof NonRetriableError_1.NonRetriableError) {
|
|
334
|
+
return {
|
|
335
|
+
status: 400,
|
|
336
|
+
error: JSON.stringify({
|
|
337
|
+
message: err.message,
|
|
338
|
+
stack: err.stack,
|
|
339
|
+
name: err.name,
|
|
340
|
+
cause: err.cause
|
|
341
|
+
? err.cause instanceof Error
|
|
342
|
+
? err.cause.stack || err.cause.message
|
|
343
|
+
: JSON.stringify(err.cause)
|
|
344
|
+
: undefined,
|
|
345
|
+
}),
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
if (err instanceof Error) {
|
|
349
|
+
return {
|
|
350
|
+
status: 500,
|
|
351
|
+
error: err.stack || err.message,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
status: 500,
|
|
356
|
+
error: `Unknown error: ${JSON.stringify(err)}`,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
configs(url) {
|
|
361
|
+
return Object.values(this.fns).map((fn) => fn["getConfig"](url, this.name));
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Returns an SDK header split in to three parts so that they can be used for
|
|
365
|
+
* different purposes.
|
|
366
|
+
*
|
|
367
|
+
* To use the entire string, run `this.sdkHeader.join("")`.
|
|
368
|
+
*/
|
|
369
|
+
get sdkHeader() {
|
|
370
|
+
return ["inngest-", `js:v${version_1.version}`, ` (${this.frameworkName})`];
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Return an Inngest serve endpoint URL given a potential `path` and `host`.
|
|
374
|
+
*
|
|
375
|
+
* Will automatically use the `serveHost` and `servePath` if they have been
|
|
376
|
+
* set when registering.
|
|
377
|
+
*/
|
|
378
|
+
reqUrl(url) {
|
|
379
|
+
let ret = new URL(url);
|
|
380
|
+
if (this.servePath)
|
|
381
|
+
ret.pathname = this.servePath;
|
|
382
|
+
if (this.serveHost)
|
|
383
|
+
ret = new URL(ret.pathname + ret.search, this.serveHost);
|
|
384
|
+
/**
|
|
385
|
+
* Remove any introspection query strings.
|
|
386
|
+
*/
|
|
387
|
+
ret.searchParams.delete(consts_1.queryKeys.Introspect);
|
|
388
|
+
return ret;
|
|
389
|
+
}
|
|
390
|
+
registerBody(url) {
|
|
391
|
+
const body = {
|
|
392
|
+
url: url.href,
|
|
393
|
+
deployType: "ping",
|
|
394
|
+
framework: this.frameworkName,
|
|
395
|
+
appName: this.name,
|
|
396
|
+
functions: this.configs(url),
|
|
397
|
+
sdk: this.sdkHeader[1],
|
|
398
|
+
v: "0.1",
|
|
399
|
+
};
|
|
400
|
+
// Calculate the checksum of the body... without the checksum itself being included.
|
|
401
|
+
body.hash = (0, hash_js_1.sha256)().update(JSON.stringify(body)).digest("hex");
|
|
402
|
+
return body;
|
|
403
|
+
}
|
|
404
|
+
async register(url, devServerHost, deployId) {
|
|
405
|
+
const body = this.registerBody(url);
|
|
406
|
+
let res;
|
|
407
|
+
// Whenever we register, we check to see if the dev server is up. This
|
|
408
|
+
// is a noop and returns false in production.
|
|
409
|
+
let registerURL = this.inngestRegisterUrl;
|
|
410
|
+
if (!this.isProd) {
|
|
411
|
+
const hasDevServer = await (0, devserver_1.devServerAvailable)(devServerHost, this.fetch);
|
|
412
|
+
if (hasDevServer) {
|
|
413
|
+
registerURL = (0, devserver_1.devServerUrl)(devServerHost, "/fn/register");
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (deployId) {
|
|
417
|
+
registerURL.searchParams.set("deployId", deployId);
|
|
418
|
+
}
|
|
419
|
+
try {
|
|
420
|
+
res = await this.fetch(registerURL.href, {
|
|
421
|
+
method: "POST",
|
|
422
|
+
body: JSON.stringify(body),
|
|
423
|
+
headers: Object.assign(Object.assign({}, this.headers), { Authorization: `Bearer ${this.hashedSigningKey}` }),
|
|
424
|
+
redirect: "follow",
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
catch (err) {
|
|
428
|
+
console.error(err);
|
|
429
|
+
return {
|
|
430
|
+
status: 500,
|
|
431
|
+
message: `Failed to register${err instanceof Error ? `; ${err.message}` : ""}`,
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
435
|
+
let data = {};
|
|
436
|
+
try {
|
|
437
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
438
|
+
data = await res.json();
|
|
439
|
+
}
|
|
440
|
+
catch (err) {
|
|
441
|
+
console.warn("Couldn't unpack register response:", err);
|
|
442
|
+
}
|
|
443
|
+
const { status, error, skipped } = registerResSchema.parse(data);
|
|
444
|
+
// The dev server polls this endpoint to register functions every few
|
|
445
|
+
// seconds, but we only want to log that we've registered functions if
|
|
446
|
+
// the function definitions change. Therefore, we compare the body sent
|
|
447
|
+
// during registration with the body of the current functions and refuse
|
|
448
|
+
// to register if the functions are the same.
|
|
449
|
+
if (!skipped) {
|
|
450
|
+
console.log("registered inngest functions:", res.status, res.statusText, data);
|
|
451
|
+
}
|
|
452
|
+
return { status, message: error };
|
|
453
|
+
}
|
|
454
|
+
get isProd() {
|
|
455
|
+
return this._isProd;
|
|
456
|
+
}
|
|
457
|
+
upsertSigningKeyFromEnv(env) {
|
|
458
|
+
if (!this.signingKey && env[consts_1.envKeys.SigningKey]) {
|
|
459
|
+
this.signingKey = env[consts_1.envKeys.SigningKey];
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
shouldShowLandingPage(strEnvVar) {
|
|
463
|
+
var _a, _b;
|
|
464
|
+
return (_b = (_a = this.showLandingPage) !== null && _a !== void 0 ? _a : (0, scalar_1.strBoolean)(strEnvVar)) !== null && _b !== void 0 ? _b : true;
|
|
465
|
+
}
|
|
466
|
+
validateSignature() {
|
|
467
|
+
return true;
|
|
468
|
+
}
|
|
469
|
+
signResponse() {
|
|
470
|
+
return "";
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
exports.InngestCommHandler = InngestCommHandler;
|
|
474
|
+
//# sourceMappingURL=InngestCommHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InngestCommHandler.js","sourceRoot":"","sources":["../../src/components/InngestCommHandler.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,6BAAwB;AACxB,8CAAuD;AACvD,oDAAwE;AACxE,8CAA+C;AAE/C,wCAAqC;AAQrC,wCAAqC;AAGrC,2DAAwD;AAoDxD;;GAEG;AACH,MAAM,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACjC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC;IAC/B,OAAO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SACzB;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,IAAI,CAAC,oCAAoC,EAAE,GAAG,CAAC,CAAC;SACzD;QACD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEjE,qEAAqE;QACrE,sEAAsE;QACtE,wEAAwE;QACxE,wEAAwE;QACxE,6CAA6C;QAC7C,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,CAAC,GAAG,CACT,+BAA+B,EAC/B,GAAG,CAAC,MAAM,EACV,GAAG,CAAC,UAAU,EACd,IAAI,CACL,CAAC;SACH;QAED,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IACpC,CAAC;IAED,IAAY,MAAM;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEO,uBAAuB,CAAC,GAAuC;QACrE,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,GAAG,CAAC,gBAAO,CAAC,UAAU,CAAC,EAAE;YAC/C,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,gBAAO,CAAC,UAAU,CAAC,CAAC;SAC3C;IACH,CAAC;IAES,qBAAqB,CAAC,SAA6B;;QAC3D,OAAO,MAAA,MAAA,IAAI,CAAC,eAAe,mCAAI,IAAA,mBAAU,EAAC,SAAS,CAAC,mCAAI,IAAI,CAAC;IAC/D,CAAC;IAES,iBAAiB;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAES,YAAY;QACpB,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AApoBD,gDAooBC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Jsonify } from "type-fest";
|
|
1
2
|
import type { ObjectPaths } from "../helpers/types";
|
|
2
3
|
import { EventPayload, HashedOp, OpStack } from "../types";
|
|
3
4
|
/**
|
|
@@ -49,7 +50,7 @@ export declare const createStepTools: <Events extends Record<string, EventPayloa
|
|
|
49
50
|
* of the `run` tool, meaning you can return and reason about return data
|
|
50
51
|
* for next steps.
|
|
51
52
|
*/
|
|
52
|
-
run: <T extends (...args: any[]) => any>(name: string, fn: T) => T extends (...args: any[]) => Promise<infer U> ? Awaited<U extends void ? null : U> : ReturnType<T> extends void ? null : ReturnType<T
|
|
53
|
+
run: <T extends (...args: any[]) => any>(name: string, fn: T) => Jsonify<T extends (...args: any[]) => Promise<infer U> ? Awaited<U extends void ? null : U> : ReturnType<T> extends void ? null : ReturnType<T>>;
|
|
53
54
|
/**
|
|
54
55
|
* Wait a specified amount of time before continuing.
|
|
55
56
|
*
|
|
@@ -64,9 +65,10 @@ export declare const createStepTools: <Events extends Record<string, EventPayloa
|
|
|
64
65
|
/**
|
|
65
66
|
* Wait until a particular date before continuing by passing a `Date`.
|
|
66
67
|
*
|
|
67
|
-
* To wait for a particular amount of time, use `sleep`
|
|
68
|
+
* To wait for a particular amount of time from now, always use `sleep`
|
|
69
|
+
* instead.
|
|
68
70
|
*/
|
|
69
|
-
sleepUntil: (time: Date) => void;
|
|
71
|
+
sleepUntil: (time: Date | string) => void;
|
|
70
72
|
}, {
|
|
71
73
|
nextOp: Promise<HashedOp> | undefined;
|
|
72
74
|
}];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestStepTools.d.ts","sourceRoot":"","sources":["../../src/components/InngestStepTools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"InngestStepTools.d.ts","sourceRoot":"","sources":["../../src/components/InngestStepTools.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAM,OAAO,EAAc,MAAM,UAAU,CAAC;AAE3E;;;GAGG;AACH,qBAAa,iBAAiB;CAAG;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,gGAIhB,OAAO;IA8Lf;;;;;;;;OAQG;;;;;;IAwDH;;;;;;;;;;;OAWG;8BAEoB,GAAG,EAAE,KAAK,GAAG,QAM1B,MAAM,wCAYQ,GAAG,EAAE;IAkB7B;;;;;;;;;OASG;kBAMO,MAAM,GAAG,MAAM,KAClB,IAAI;IAYX;;;;;OAKG;uBAMO,IAAI,GAAG,MAAM,KAChB,IAAI;;YArKH,QAAQ,QAAQ,CAAC,GAAG,SAAS;EAiMxC,CAAC;AAEF;;;GAGG;AACH,UAAU,gBAAgB,CACxB,eAAe,SAAS,YAAY,EACpC,aAAa,SAAS,YAAY;IAElC;;;;;;;;;OASG;IACH,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAEhC;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC,eAAe,CAAC,GAAG,WAAW,CAAC,aAAa,CAAC,CAAC;IAElE;;;;;;;;;;;OAWG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;CACb"}
|
|
@@ -246,17 +246,29 @@ const createStepTools = (_opStack) => {
|
|
|
246
246
|
/**
|
|
247
247
|
* Wait until a particular date before continuing by passing a `Date`.
|
|
248
248
|
*
|
|
249
|
-
* To wait for a particular amount of time, use `sleep`
|
|
249
|
+
* To wait for a particular amount of time from now, always use `sleep`
|
|
250
|
+
* instead.
|
|
250
251
|
*/
|
|
251
252
|
sleepUntil: createTool((time) => {
|
|
253
|
+
const date = typeof time === "string" ? new Date(time) : time;
|
|
252
254
|
/**
|
|
253
255
|
* The presence of this operation in the returned stack indicates that the
|
|
254
256
|
* sleep is over and we should continue execution.
|
|
255
257
|
*/
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
try {
|
|
259
|
+
return {
|
|
260
|
+
op: types_1.StepOpCode.Sleep,
|
|
261
|
+
name: date.toISOString(),
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
/**
|
|
266
|
+
* If we're here, it's because the date is invalid. We'll throw a custom
|
|
267
|
+
* error here to standardise this response.
|
|
268
|
+
*/
|
|
269
|
+
console.warn("Invalid date or date string passed to sleepUntil;", err);
|
|
270
|
+
throw new Error(`Invalid date or date string passed to sleepUntil: ${time.toString()}`);
|
|
271
|
+
}
|
|
260
272
|
}),
|
|
261
273
|
};
|
|
262
274
|
return [tools, state];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestStepTools.js","sourceRoot":"","sources":["../../src/components/InngestStepTools.ts"],"names":[],"mappings":";;;;;;AAAA,qCAA+B;AAC/B,sDAA8B;
|
|
1
|
+
{"version":3,"file":"InngestStepTools.js","sourceRoot":"","sources":["../../src/components/InngestStepTools.ts"],"names":[],"mappings":";;;;;;AAAA,qCAA+B;AAC/B,sDAA8B;AAE9B,gDAA6C;AAE7C,oCAA2E;AAE3E;;;GAGG;AACH,MAAa,iBAAiB;CAAG;AAAjC,8CAAiC;AAEjC;;;;;;;;;;;;;;;GAeG;AACI,MAAM,eAAe,GAAG,CAI7B,QAAiB,EACjB,EAAE;IACF;;;;;;;;;;;OAWG;IACH,IAAI,gBAAgB,GAAG,IAAI,CAAC;IAE5B;;;;;;OAMG;IACH,IAAI,GAAG,GAAG,CAAC,CAAC;IAEZ;;;OAGG;IACH,MAAM,OAAO,qBAAQ,QAAQ,CAAE,CAAC;IAEhC;;;;;OAKG;IACH,MAAM,iBAAiB,GAAG,CACxB,EAAY,EACgD,EAAE;QAC9D,MAAM,IAAI,GAAY,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACrC,iEAAiE;QACjE,kEAAkE;QAClE,uBAAuB;QACvB,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,IAAW,CAAC,CAAC;IAC3C,CAAC,CAAC;IAEF;;;;;;;;OAQG;IACH,MAAM,UAAU,GAAG;IACjB;;;;;;;;OAQG;IACH,OAKO;IAEP;;;;;;;;;;OAUG;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EAAC,IAAI,CAAC;aACpB,CAAC;QACJ,CAAC,CAAC;QAEF;;;;;WAKG;QACH,UAAU,EAAE,UAAU,CAOpB,CAAC,IAAI,EAAE,EAAE;YACT,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAE9D;;;eAGG;YACH,IAAI;gBACF,OAAO;oBACL,EAAE,EAAE,kBAAU,CAAC,KAAK;oBACpB,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE;iBACzB,CAAC;aACH;YAAC,OAAO,GAAG,EAAE;gBACZ;;;mBAGG;gBACH,OAAO,CAAC,IAAI,CAAC,mDAAmD,EAAE,GAAG,CAAC,CAAC;gBAEvE,MAAM,IAAI,KAAK,CACb,qDAAqD,IAAI,CAAC,QAAQ,EAAE,EAAE,CACvE,CAAC;aACH;QACH,CAAC,CAAC;KACH,CAAC;IAEF,OAAO,CAAC,KAAK,EAAE,KAAK,CAAiC,CAAC;AACxD,CAAC,CAAC;AAvXW,QAAA,eAAe,mBAuX1B;AA4DF;;;;GAIG;AACH,MAAM,MAAM,GAAG;AACb;;;GAGG;AACH,EAAM;AAEN;;;;GAIG;AACH,GAAW,EACH,EAAE;IACV,OAAO,CACL,IAAA,cAAI,GAAE;QACJ,mEAAmE;SAClE,MAAM,CAAC,IAAA,iBAAO,EAAC,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;SACjE,MAAM,CAAC,KAAK,CAAC,CACjB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An error that, when thrown, indicates to Inngest that the function should
|
|
3
|
+
* cease all execution and not retry.
|
|
4
|
+
*
|
|
5
|
+
* A `message` must be provided, and an optional `cause` can be provided to
|
|
6
|
+
* provide more context to the error.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare class NonRetriableError extends Error {
|
|
11
|
+
/**
|
|
12
|
+
* The underlying cause of the error, if any.
|
|
13
|
+
*
|
|
14
|
+
* This will be serialized and sent to Inngest.
|
|
15
|
+
*/
|
|
16
|
+
readonly cause?: any;
|
|
17
|
+
constructor(message: string, options?: {
|
|
18
|
+
/**
|
|
19
|
+
* The underlying cause of the error, if any.
|
|
20
|
+
*
|
|
21
|
+
* This will be serialized and sent to Inngest.
|
|
22
|
+
*/
|
|
23
|
+
cause?: any;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=NonRetriableError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NonRetriableError.d.ts","sourceRoot":"","sources":["../../src/components/NonRetriableError.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C;;;;OAIG;IACH,SAAgB,KAAK,CAAC,EAAE,GAAG,CAAC;gBAG1B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR;;;;WAIG;QACH,KAAK,CAAC,EAAE,GAAG,CAAC;KACb;CAMJ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NonRetriableError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* An error that, when thrown, indicates to Inngest that the function should
|
|
6
|
+
* cease all execution and not retry.
|
|
7
|
+
*
|
|
8
|
+
* A `message` must be provided, and an optional `cause` can be provided to
|
|
9
|
+
* provide more context to the error.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
class NonRetriableError extends Error {
|
|
14
|
+
constructor(message, options) {
|
|
15
|
+
super(message);
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
17
|
+
this.cause = options === null || options === void 0 ? void 0 : options.cause;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.NonRetriableError = NonRetriableError;
|
|
21
|
+
//# sourceMappingURL=NonRetriableError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NonRetriableError.js","sourceRoot":"","sources":["../../src/components/NonRetriableError.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAQ1C,YACE,OAAe,EACf,OAOC;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,mEAAmE;QACnE,IAAI,CAAC,KAAK,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAC;IAC9B,CAAC;CACF;AAvBD,8CAuBC"}
|
package/deno/fresh.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ServeHandler } from "../components/InngestCommHandler";
|
|
2
|
+
/**
|
|
3
|
+
* With Deno's Fresh framework, serve and register any declared functions with
|
|
4
|
+
* Inngest, making them available to be triggered by events.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare const serve: ServeHandler;
|
|
9
|
+
//# sourceMappingURL=fresh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fresh.d.ts","sourceRoot":"","sources":["../../src/deno/fresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACb,MAAM,kCAAkC,CAAC;AAG1C;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,YAkDnB,CAAC"}
|