inngest 0.8.9 → 0.9.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/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 +451 -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/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/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 +2 -0
- package/index.d.ts.map +1 -1
- package/index.js +3 -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 +10 -10
- package/types.d.ts.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/express.d.ts
CHANGED
|
@@ -1,129 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InngestFunction } from "./components/InngestFunction";
|
|
3
|
-
import type { FunctionConfig, RegisterOptions, RegisterRequest, StepRunResponse } from "./types";
|
|
4
|
-
/**
|
|
5
|
-
* A handler for serving Inngest functions. This type should be used
|
|
6
|
-
* whenever a handler for a new framework is being added to enforce that the
|
|
7
|
-
* registration process is always the same for the user.
|
|
8
|
-
*
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
11
|
-
export declare type ServeHandler = (
|
|
12
|
-
/**
|
|
13
|
-
* The name of this app, used to scope and group Inngest functions, or
|
|
14
|
-
* the `Inngest` instance used to declare all functions.
|
|
15
|
-
*/
|
|
16
|
-
nameOrInngest: string | Inngest<any>,
|
|
17
|
-
/**
|
|
18
|
-
* An array of the functions to serve and register with Inngest.
|
|
19
|
-
*/
|
|
20
|
-
functions: InngestFunction<any>[],
|
|
21
|
-
/**
|
|
22
|
-
* A set of options to further configure the registration of Inngest
|
|
23
|
-
* functions.
|
|
24
|
-
*/
|
|
25
|
-
opts?: RegisterOptions) => any;
|
|
1
|
+
import { ServeHandler } from "./components/InngestCommHandler";
|
|
26
2
|
/**
|
|
27
3
|
* Serve and register any declared functions with Inngest, making them available
|
|
28
4
|
* to be triggered by events.
|
|
29
5
|
*
|
|
30
|
-
* Can either take an `Inngest` instance and a signing key, or can be used to
|
|
31
|
-
* create custom handlers by passing in an `InngestCommHandler`.
|
|
32
|
-
*
|
|
33
|
-
* @public
|
|
34
|
-
*/
|
|
35
|
-
export declare const serve: (...args: Parameters<ServeHandler> | [commHandler: InngestCommHandler]) => any;
|
|
36
|
-
/**
|
|
37
|
-
* TODO Instead of `createHandler`, expose `createRequest` and `handleResponse`
|
|
38
|
-
*
|
|
39
|
-
* Overriding `createHandler` requires that we always remember crucial steps,
|
|
40
|
-
* e.g. validating signatures, handling POST, etc.
|
|
41
|
-
*
|
|
42
|
-
* We should instead require that new comm handlers override only two functions:
|
|
43
|
-
*
|
|
44
|
-
* `createRequest()`
|
|
45
|
-
* This is the function that is exposed. It must return a valid `HandlerRequest`
|
|
46
|
-
*
|
|
47
|
-
* `handleResponse()`
|
|
48
|
-
* The input is a `StepResponse`, and output can be anything needed for the
|
|
49
|
-
* platform
|
|
50
|
-
*
|
|
51
|
-
* This needs to also account for the ability to validate signatures etc.
|
|
52
|
-
*
|
|
53
6
|
* @public
|
|
54
7
|
*/
|
|
55
|
-
export declare
|
|
56
|
-
name: string;
|
|
57
|
-
/**
|
|
58
|
-
* The URL of the Inngest function registration endpoint.
|
|
59
|
-
*/
|
|
60
|
-
private readonly inngestRegisterUrl;
|
|
61
|
-
protected readonly frameworkName: string;
|
|
62
|
-
protected signingKey: string | undefined;
|
|
63
|
-
/**
|
|
64
|
-
* A property that can be set to indicate whether or not we believe we are in
|
|
65
|
-
* production mode.
|
|
66
|
-
*
|
|
67
|
-
* Should be set every time a request is received.
|
|
68
|
-
*/
|
|
69
|
-
protected _isProd: boolean;
|
|
70
|
-
private readonly headers;
|
|
71
|
-
private readonly fetch;
|
|
72
|
-
/**
|
|
73
|
-
* Whether we should show the SDK Landing Page.
|
|
74
|
-
*
|
|
75
|
-
* This purposefully does not take in to account any environment variables, as
|
|
76
|
-
* accessing them safely is platform-specific.
|
|
77
|
-
*/
|
|
78
|
-
protected readonly showLandingPage: boolean | undefined;
|
|
79
|
-
protected readonly serveHost: string | undefined;
|
|
80
|
-
protected readonly servePath: string | undefined;
|
|
81
|
-
/**
|
|
82
|
-
* A private collection of functions that are being served. This map is used
|
|
83
|
-
* to find and register functions when interacting with Inngest Cloud.
|
|
84
|
-
*/
|
|
85
|
-
private readonly fns;
|
|
86
|
-
constructor(nameOrInngest: string | Inngest<any>, functions: InngestFunction<any>[], { inngestRegisterUrl, fetch, landingPage, signingKey, serveHost, servePath, }?: RegisterOptions);
|
|
87
|
-
private get hashedSigningKey();
|
|
88
|
-
createHandler(): any;
|
|
89
|
-
protected runStep(functionId: string, stepId: string, data: any): Promise<StepRunResponse>;
|
|
90
|
-
protected configs(url: URL): FunctionConfig[];
|
|
91
|
-
/**
|
|
92
|
-
* Returns an SDK header split in to three parts so that they can be used for
|
|
93
|
-
* different purposes.
|
|
94
|
-
*
|
|
95
|
-
* To use the entire string, run `this.sdkHeader.join("")`.
|
|
96
|
-
*/
|
|
97
|
-
protected get sdkHeader(): [
|
|
98
|
-
prefix: string,
|
|
99
|
-
version: RegisterRequest["sdk"],
|
|
100
|
-
suffix: string
|
|
101
|
-
];
|
|
102
|
-
/**
|
|
103
|
-
* Return an Inngest serve endpoint URL given a potential `path` and `host`.
|
|
104
|
-
*
|
|
105
|
-
* Will automatically use the `serveHost` and `servePath` if they have been
|
|
106
|
-
* set when registering.
|
|
107
|
-
*/
|
|
108
|
-
protected reqUrl(
|
|
109
|
-
/**
|
|
110
|
-
* The path of the Inngest register URL to create. Regardless of the value,
|
|
111
|
-
* will be overwritten by `servePath` if it has been set.
|
|
112
|
-
*/
|
|
113
|
-
path?: string,
|
|
114
|
-
/**
|
|
115
|
-
* The host of the Inngest register URL to create. Regardless of the value,
|
|
116
|
-
* will be overwritten by `serveHost` if it has been set.
|
|
117
|
-
*/
|
|
118
|
-
host?: string): URL;
|
|
119
|
-
protected registerBody(url: URL): RegisterRequest;
|
|
120
|
-
protected register(url: URL, devServerHost: string | undefined): Promise<{
|
|
121
|
-
status: number;
|
|
122
|
-
message: string;
|
|
123
|
-
}>;
|
|
124
|
-
private get isProd();
|
|
125
|
-
protected shouldShowLandingPage(strEnvVar: string | undefined): boolean;
|
|
126
|
-
protected validateSignature(): boolean;
|
|
127
|
-
protected signResponse(): string;
|
|
128
|
-
}
|
|
8
|
+
export declare const serve: ServeHandler;
|
|
129
9
|
//# sourceMappingURL=express.d.ts.map
|
package/express.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,YAAY,EACb,MAAM,iCAAiC,CAAC;AAIzC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,YA6DnB,CAAC"}
|
package/express.js
CHANGED
|
@@ -1,317 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const zod_1 = require("zod");
|
|
3
|
+
exports.serve = void 0;
|
|
4
|
+
const InngestCommHandler_1 = require("./components/InngestCommHandler");
|
|
6
5
|
const consts_1 = require("./helpers/consts");
|
|
7
|
-
const
|
|
8
|
-
const scalar_1 = require("./helpers/scalar");
|
|
9
|
-
const landing_1 = require("./landing");
|
|
10
|
-
const version_1 = require("./version");
|
|
11
|
-
/**
|
|
12
|
-
* A schema for the response from Inngest when registering.
|
|
13
|
-
*/
|
|
14
|
-
const registerResSchema = zod_1.z.object({
|
|
15
|
-
status: zod_1.z.number().default(200),
|
|
16
|
-
skipped: zod_1.z.boolean().optional().default(false),
|
|
17
|
-
error: zod_1.z.string().default("Successfully registered"),
|
|
18
|
-
});
|
|
6
|
+
const env_1 = require("./helpers/env");
|
|
19
7
|
/**
|
|
20
8
|
* Serve and register any declared functions with Inngest, making them available
|
|
21
9
|
* to be triggered by events.
|
|
22
10
|
*
|
|
23
|
-
* Can either take an `Inngest` instance and a signing key, or can be used to
|
|
24
|
-
* create custom handlers by passing in an `InngestCommHandler`.
|
|
25
|
-
*
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
const serve = (...args) => {
|
|
29
|
-
if (args.length === 1) {
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
31
|
-
return args[0].createHandler();
|
|
32
|
-
}
|
|
33
|
-
const [nameOrInngest, fns, opts] = args;
|
|
34
|
-
const handler = new InngestCommHandler(nameOrInngest, fns, opts);
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
36
|
-
return handler.createHandler();
|
|
37
|
-
};
|
|
38
|
-
exports.serve = serve;
|
|
39
|
-
/**
|
|
40
|
-
* TODO Instead of `createHandler`, expose `createRequest` and `handleResponse`
|
|
41
|
-
*
|
|
42
|
-
* Overriding `createHandler` requires that we always remember crucial steps,
|
|
43
|
-
* e.g. validating signatures, handling POST, etc.
|
|
44
|
-
*
|
|
45
|
-
* We should instead require that new comm handlers override only two functions:
|
|
46
|
-
*
|
|
47
|
-
* `createRequest()`
|
|
48
|
-
* This is the function that is exposed. It must return a valid `HandlerRequest`
|
|
49
|
-
*
|
|
50
|
-
* `handleResponse()`
|
|
51
|
-
* The input is a `StepResponse`, and output can be anything needed for the
|
|
52
|
-
* platform
|
|
53
|
-
*
|
|
54
|
-
* This needs to also account for the ability to validate signatures etc.
|
|
55
|
-
*
|
|
56
11
|
* @public
|
|
57
12
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this.fns = functions.reduce((acc, fn) => {
|
|
76
|
-
const id = fn.id(this.name);
|
|
77
|
-
if (acc[id]) {
|
|
78
|
-
throw new Error(`Duplicate function ID "${id}"; please change a function's name or provide an explicit ID to avoid conflicts.`);
|
|
79
|
-
}
|
|
80
|
-
return Object.assign(Object.assign({}, acc), { [id]: fn });
|
|
81
|
-
}, {});
|
|
82
|
-
this.inngestRegisterUrl = new URL(inngestRegisterUrl || "https://api.inngest.com/fn/register");
|
|
83
|
-
this.signingKey = signingKey;
|
|
84
|
-
this.showLandingPage = landingPage;
|
|
85
|
-
this.serveHost = serveHost;
|
|
86
|
-
this.servePath = servePath;
|
|
87
|
-
this.headers = {
|
|
88
|
-
"Content-Type": "application/json",
|
|
89
|
-
"User-Agent": `inngest-js:v${version_1.version} (${this.frameworkName})`,
|
|
90
|
-
};
|
|
91
|
-
this.fetch =
|
|
92
|
-
fetch ||
|
|
93
|
-
(typeof nameOrInngest === "string"
|
|
94
|
-
? undefined
|
|
95
|
-
: nameOrInngest["fetch"]) ||
|
|
96
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
97
|
-
require("cross-fetch");
|
|
98
|
-
}
|
|
99
|
-
// hashedSigningKey creates a sha256 checksum of the signing key with the
|
|
100
|
-
// same signing key prefix.
|
|
101
|
-
get hashedSigningKey() {
|
|
102
|
-
var _a;
|
|
103
|
-
if (!this.signingKey) {
|
|
104
|
-
return "";
|
|
105
|
-
}
|
|
106
|
-
const prefix = ((_a = this.signingKey.match(/^signkey-(test|prod)-/)) === null || _a === void 0 ? void 0 : _a.shift()) || "";
|
|
107
|
-
const key = this.signingKey.replace(/^signkey-(test|prod)-/, "");
|
|
108
|
-
// Decode the key from its hex representation into a bytestream
|
|
109
|
-
return `${prefix}${(0, hash_js_1.sha256)().update(key, "hex").digest("hex")}`;
|
|
110
|
-
}
|
|
111
|
-
createHandler() {
|
|
112
|
-
return async (req, res) => {
|
|
113
|
-
res.setHeader("x-inngest-sdk", this.sdkHeader.join(""));
|
|
114
|
-
const hostname = req.get("host") || req.headers["host"];
|
|
115
|
-
const protocol = (hostname === null || hostname === void 0 ? void 0 : hostname.includes("://")) ? "" : `${req.protocol}://`;
|
|
116
|
-
let reqUrl;
|
|
117
|
-
try {
|
|
118
|
-
reqUrl = this.reqUrl(req.originalUrl, `${protocol}${hostname || ""}`);
|
|
119
|
-
reqUrl.searchParams.delete(consts_1.queryKeys.Introspect);
|
|
120
|
-
}
|
|
121
|
-
catch (e) {
|
|
122
|
-
const message = "Unable to determine your site URL to serve the Inngest handler.";
|
|
123
|
-
console.error(message);
|
|
124
|
-
return res.status(500).json({ message });
|
|
125
|
-
}
|
|
126
|
-
if (!this.signingKey && process.env[consts_1.envKeys.SigningKey]) {
|
|
127
|
-
this.signingKey = process.env[consts_1.envKeys.SigningKey];
|
|
128
|
-
}
|
|
129
|
-
this._isProd =
|
|
130
|
-
process.env.ENVIRONMENT === "production" ||
|
|
131
|
-
process.env.NODE_ENV === "production";
|
|
132
|
-
switch (req.method) {
|
|
133
|
-
case "GET": {
|
|
134
|
-
const showLandingPage = this.shouldShowLandingPage(process.env[consts_1.envKeys.LandingPage]);
|
|
135
|
-
if (this._isProd || !showLandingPage)
|
|
136
|
-
break;
|
|
137
|
-
if (Object.hasOwnProperty.call(req.query, consts_1.queryKeys.Introspect)) {
|
|
138
|
-
const introspection = Object.assign(Object.assign({}, this.registerBody(reqUrl)), { devServerURL: (0, devserver_1.devServerUrl)(process.env[consts_1.envKeys.DevServerUrl])
|
|
139
|
-
.href, hasSigningKey: Boolean(this.signingKey) });
|
|
140
|
-
return void res.status(200).json(introspection);
|
|
141
|
-
}
|
|
142
|
-
// Grab landing page and serve
|
|
143
|
-
res.header("content-type", "text/html; charset=utf-8");
|
|
144
|
-
return void res.status(200).send(landing_1.landing);
|
|
13
|
+
const serve = (nameOrInngest, fns, opts) => {
|
|
14
|
+
const handler = new InngestCommHandler_1.InngestCommHandler("express", nameOrInngest, fns, opts, (req, _res) => {
|
|
15
|
+
const hostname = req.get("host") || req.headers["host"];
|
|
16
|
+
const protocol = (hostname === null || hostname === void 0 ? void 0 : hostname.includes("://")) ? "" : `${req.protocol}://`;
|
|
17
|
+
const url = new URL(req.originalUrl, `${protocol}${hostname || ""}`);
|
|
18
|
+
const env = (0, env_1.allProcessEnv)();
|
|
19
|
+
const isProduction = env.ENVIRONMENT === "production" || env.NODE_ENV === "production";
|
|
20
|
+
return {
|
|
21
|
+
run: () => {
|
|
22
|
+
if (req.method === "POST") {
|
|
23
|
+
return {
|
|
24
|
+
fnId: req.query[consts_1.queryKeys.FnId],
|
|
25
|
+
data: req.body,
|
|
26
|
+
env,
|
|
27
|
+
isProduction,
|
|
28
|
+
url,
|
|
29
|
+
};
|
|
145
30
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
31
|
+
},
|
|
32
|
+
register: () => {
|
|
33
|
+
var _a;
|
|
34
|
+
if (req.method === "PUT") {
|
|
35
|
+
return {
|
|
36
|
+
env,
|
|
37
|
+
url,
|
|
38
|
+
isProduction,
|
|
39
|
+
deployId: (_a = req.query[consts_1.queryKeys.DeployId]) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
40
|
+
};
|
|
150
41
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
stepId: req.query[consts_1.queryKeys.StepId],
|
|
161
|
-
});
|
|
162
|
-
const stepRes = await this.runStep(fnId, stepId, req.body);
|
|
163
|
-
if (stepRes.status === 500) {
|
|
164
|
-
return void res.status(stepRes.status).json(stepRes.error);
|
|
165
|
-
}
|
|
166
|
-
return void res.status(stepRes.status).json(stepRes.body);
|
|
42
|
+
},
|
|
43
|
+
view: () => {
|
|
44
|
+
if (req.method === "GET") {
|
|
45
|
+
return {
|
|
46
|
+
env,
|
|
47
|
+
url,
|
|
48
|
+
isIntrospection: Object.hasOwnProperty.call(req.query, consts_1.queryKeys.Introspect),
|
|
49
|
+
isProduction,
|
|
50
|
+
};
|
|
167
51
|
}
|
|
168
|
-
}
|
|
169
|
-
return void res.sendStatus(405);
|
|
52
|
+
},
|
|
170
53
|
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const fn = this.fns[functionId];
|
|
175
|
-
if (!fn) {
|
|
176
|
-
throw new Error(`Could not find function with ID "${functionId}"`);
|
|
177
|
-
}
|
|
178
|
-
const { event, steps } = zod_1.z
|
|
179
|
-
.object({
|
|
180
|
-
event: zod_1.z.object({}).passthrough(),
|
|
181
|
-
steps: zod_1.z.object({}).passthrough().optional().nullable(),
|
|
182
|
-
})
|
|
183
|
-
.parse(data);
|
|
184
|
-
const ret = await fn["runFn"]({ event }, steps || {});
|
|
185
|
-
const isOp = ret[0];
|
|
186
|
-
if (isOp) {
|
|
187
|
-
return {
|
|
188
|
-
status: 206,
|
|
189
|
-
body: ret[1],
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
return {
|
|
193
|
-
status: 200,
|
|
194
|
-
body: ret[1],
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
catch (err) {
|
|
198
|
-
if (err instanceof Error) {
|
|
199
|
-
return {
|
|
200
|
-
status: 500,
|
|
201
|
-
error: err.stack || err.message,
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
return {
|
|
205
|
-
status: 500,
|
|
206
|
-
error: `Unknown error: ${JSON.stringify(err)}`,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
configs(url) {
|
|
211
|
-
return Object.values(this.fns).map((fn) => fn["getConfig"](url, this.name));
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Returns an SDK header split in to three parts so that they can be used for
|
|
215
|
-
* different purposes.
|
|
216
|
-
*
|
|
217
|
-
* To use the entire string, run `this.sdkHeader.join("")`.
|
|
218
|
-
*/
|
|
219
|
-
get sdkHeader() {
|
|
220
|
-
return ["inngest-", `js:v${version_1.version}`, ` (${this.frameworkName})`];
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Return an Inngest serve endpoint URL given a potential `path` and `host`.
|
|
224
|
-
*
|
|
225
|
-
* Will automatically use the `serveHost` and `servePath` if they have been
|
|
226
|
-
* set when registering.
|
|
227
|
-
*/
|
|
228
|
-
reqUrl(
|
|
229
|
-
/**
|
|
230
|
-
* The path of the Inngest register URL to create. Regardless of the value,
|
|
231
|
-
* will be overwritten by `servePath` if it has been set.
|
|
232
|
-
*/
|
|
233
|
-
path,
|
|
234
|
-
/**
|
|
235
|
-
* The host of the Inngest register URL to create. Regardless of the value,
|
|
236
|
-
* will be overwritten by `serveHost` if it has been set.
|
|
237
|
-
*/
|
|
238
|
-
host) {
|
|
239
|
-
return new URL(this.servePath || (path === null || path === void 0 ? void 0 : path.trim()) || "", this.serveHost || (host === null || host === void 0 ? void 0 : host.trim()) || "");
|
|
240
|
-
}
|
|
241
|
-
registerBody(url) {
|
|
242
|
-
const body = {
|
|
243
|
-
url: url.href,
|
|
244
|
-
deployType: "ping",
|
|
245
|
-
framework: this.frameworkName,
|
|
246
|
-
appName: this.name,
|
|
247
|
-
functions: this.configs(url),
|
|
248
|
-
sdk: this.sdkHeader[1],
|
|
249
|
-
v: "0.1",
|
|
250
|
-
};
|
|
251
|
-
// Calculate the checksum of the body... without the checksum itself being included.
|
|
252
|
-
body.hash = (0, hash_js_1.sha256)().update(JSON.stringify(body)).digest("hex");
|
|
253
|
-
return body;
|
|
254
|
-
}
|
|
255
|
-
async register(url, devServerHost) {
|
|
256
|
-
const body = this.registerBody(url);
|
|
257
|
-
let res;
|
|
258
|
-
// Whenever we register, we check to see if the dev server is up. This
|
|
259
|
-
// is a noop and returns false in production.
|
|
260
|
-
let registerURL = this.inngestRegisterUrl;
|
|
261
|
-
if (!this.isProd) {
|
|
262
|
-
const hasDevServer = await (0, devserver_1.devServerAvailable)(devServerHost, this.fetch);
|
|
263
|
-
if (hasDevServer) {
|
|
264
|
-
registerURL = (0, devserver_1.devServerUrl)(devServerHost, "/fn/register");
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
try {
|
|
268
|
-
res = await this.fetch(registerURL.href, {
|
|
269
|
-
method: "POST",
|
|
270
|
-
body: JSON.stringify(body),
|
|
271
|
-
headers: Object.assign(Object.assign({}, this.headers), { Authorization: `Bearer ${this.hashedSigningKey}` }),
|
|
272
|
-
redirect: "follow",
|
|
273
|
-
});
|
|
54
|
+
}, (actionRes, _req, res) => {
|
|
55
|
+
for (const [name, value] of Object.entries(actionRes.headers)) {
|
|
56
|
+
res.setHeader(name, value);
|
|
274
57
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
283
|
-
let data = {};
|
|
284
|
-
try {
|
|
285
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
286
|
-
data = await res.json();
|
|
287
|
-
}
|
|
288
|
-
catch (err) {
|
|
289
|
-
console.warn("Couldn't unpack register response:", err);
|
|
290
|
-
}
|
|
291
|
-
const { status, error, skipped } = registerResSchema.parse(data);
|
|
292
|
-
// The dev server polls this endpoint to register functions every few
|
|
293
|
-
// seconds, but we only want to log that we've registered functions if
|
|
294
|
-
// the function definitions change. Therefore, we compare the body sent
|
|
295
|
-
// during registration with the body of the current functions and refuse
|
|
296
|
-
// to register if the functions are the same.
|
|
297
|
-
if (!skipped) {
|
|
298
|
-
console.log("registered inngest functions:", res.status, res.statusText, data);
|
|
299
|
-
}
|
|
300
|
-
return { status, message: error };
|
|
301
|
-
}
|
|
302
|
-
get isProd() {
|
|
303
|
-
return this._isProd;
|
|
304
|
-
}
|
|
305
|
-
shouldShowLandingPage(strEnvVar) {
|
|
306
|
-
var _a, _b;
|
|
307
|
-
return (_b = (_a = this.showLandingPage) !== null && _a !== void 0 ? _a : (0, scalar_1.strBoolean)(strEnvVar)) !== null && _b !== void 0 ? _b : true;
|
|
308
|
-
}
|
|
309
|
-
validateSignature() {
|
|
310
|
-
return true;
|
|
311
|
-
}
|
|
312
|
-
signResponse() {
|
|
313
|
-
return "";
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
exports.InngestCommHandler = InngestCommHandler;
|
|
58
|
+
return res.status(actionRes.status).send(actionRes.body);
|
|
59
|
+
});
|
|
60
|
+
return handler.createHandler();
|
|
61
|
+
};
|
|
62
|
+
exports.serve = serve;
|
|
317
63
|
//# sourceMappingURL=express.js.map
|
package/express.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":";;;AACA,wEAGyC;AACzC,6CAA6C;AAC7C,uCAA8C;AAE9C;;;;;GAKG;AACI,MAAM,KAAK,GAAiB,CAAC,aAAa,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IAC9D,MAAM,OAAO,GAAG,IAAI,uCAAkB,CACpC,SAAS,EACT,aAAa,EACb,GAAG,EACH,IAAI,EACJ,CAAC,GAAY,EAAE,IAAc,EAAE,EAAE;QAC/B,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACxD,MAAM,QAAQ,GAAG,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAQ,CAAC,KAAK,CAAC,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,QAAQ,KAAK,CAAC;QACvE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,QAAQ,GAAG,QAAQ,IAAI,EAAE,EAAE,CAAC,CAAC;QACrE,MAAM,GAAG,GAAG,IAAA,mBAAa,GAAE,CAAC;QAC5B,MAAM,YAAY,GAChB,GAAG,CAAC,WAAW,KAAK,YAAY,IAAI,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;QAEpE,OAAO;YACL,GAAG,EAAE,GAAG,EAAE;gBACR,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE;oBACzB,OAAO;wBACL,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,kBAAS,CAAC,IAAI,CAAW;wBACzC,IAAI,EAAE,GAAG,CAAC,IAA2B;wBACrC,GAAG;wBACH,YAAY;wBACZ,GAAG;qBACJ,CAAC;iBACH;YACH,CAAC;YACD,QAAQ,EAAE,GAAG,EAAE;;gBACb,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,EAAE;oBACxB,OAAO;wBACL,GAAG;wBACH,GAAG;wBACH,YAAY;wBACZ,QAAQ,EAAE,MAAA,GAAG,CAAC,KAAK,CAAC,kBAAS,CAAC,QAAQ,CAAC,0CAAE,QAAQ,EAAE;qBACpD,CAAC;iBACH;YACH,CAAC;YACD,IAAI,EAAE,GAAG,EAAE;gBACT,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,EAAE;oBACxB,OAAO;wBACL,GAAG;wBACH,GAAG;wBACH,eAAe,EAAE,MAAM,CAAC,cAAc,CAAC,IAAI,CACzC,GAAG,CAAC,KAAK,EACT,kBAAS,CAAC,UAAU,CACrB;wBACD,YAAY;qBACb,CAAC;iBACH;YACH,CAAC;SACF,CAAC;IACJ,CAAC,EACD,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;QACvB,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;YAC7D,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;SAC5B;QAED,OAAO,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC,CACF,CAAC;IAEF,OAAO,OAAO,CAAC,aAAa,EAAE,CAAC;AACjC,CAAC,CAAC;AA7DW,QAAA,KAAK,SA6DhB"}
|
package/helpers/consts.d.ts
CHANGED
package/helpers/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../src/helpers/consts.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACnB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,UAAU,eAAe;
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../src/helpers/consts.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACnB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,UAAU,eAAe;IACzB,QAAQ,aAAa;CACtB;AAED,oBAAY,OAAO;IACjB,UAAU,wBAAwB;IAClC,QAAQ,sBAAsB;IAC9B,WAAW,yBAAyB;IACpC,YAAY,0BAA0B;CACvC;AAED,oBAAY,WAAW;IACrB,UAAU,aAAa;IACvB,YAAY,eAAe;IAC3B,aAAa,YAAY;CAC1B;AAED,eAAO,MAAM,oBAAoB,2BAA2B,CAAC"}
|
package/helpers/consts.js
CHANGED
package/helpers/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/helpers/consts.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/helpers/consts.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,0BAAa,CAAA;IACb,8BAAiB,CAAA;IACjB,sCAAyB,CAAA;IACzB,kCAAqB,CAAA;AACvB,CAAC,EALW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAKpB;AAED,IAAY,OAKX;AALD,WAAY,OAAO;IACjB,6CAAkC,CAAA;IAClC,yCAA8B,CAAA;IAC9B,+CAAoC,CAAA;IACpC,iDAAsC,CAAA;AACxC,CAAC,EALW,OAAO,GAAP,eAAO,KAAP,eAAO,QAKlB;AAED,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,sCAAuB,CAAA;IACvB,0CAA2B,CAAA;IAC3B,wCAAyB,CAAA;AAC3B,CAAC,EAJW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAItB;AAEY,QAAA,oBAAoB,GAAG,wBAAwB,CAAC"}
|
package/helpers/devserver.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { FunctionConfig } from "../types";
|
|
|
4
4
|
* to fall in to the self-referencing `const fetch: typeof fetch = ...` which
|
|
5
5
|
* fails.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
type FetchT = typeof fetch;
|
|
8
8
|
/**
|
|
9
9
|
* Attempts to contact the dev server, returning a boolean indicating whether or
|
|
10
10
|
* not it was successful.
|
|
@@ -18,11 +18,11 @@ export declare const devServerAvailable: (host: string | undefined, fetch: Fetch
|
|
|
18
18
|
* Because Cloudflare/V8 platforms don't allow process.env, you are expected
|
|
19
19
|
* to pass in the host from the dev server env key:
|
|
20
20
|
*
|
|
21
|
-
* @example devServerUrl(
|
|
21
|
+
* @example devServerUrl(processEnv(envKeys.DevServerUrl), "/your-path")
|
|
22
22
|
* @example devServerUrl("http://localhost:8288/", "/your-path")
|
|
23
23
|
*/
|
|
24
24
|
export declare const devServerUrl: (host?: string, pathname?: string) => URL;
|
|
25
|
-
export
|
|
25
|
+
export type InfoResponse = {
|
|
26
26
|
version: string;
|
|
27
27
|
startOpts: {
|
|
28
28
|
sdkURLs: string[];
|
|
@@ -35,14 +35,14 @@ export declare type InfoResponse = {
|
|
|
35
35
|
functions: FunctionConfig[];
|
|
36
36
|
handlers: SDKHandler[];
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
type WorkspaceResponse = {
|
|
39
39
|
signingKey: string;
|
|
40
40
|
eventKeys: Array<{
|
|
41
41
|
name: string;
|
|
42
42
|
key: string;
|
|
43
43
|
}>;
|
|
44
44
|
};
|
|
45
|
-
|
|
45
|
+
type SDKHandler = {
|
|
46
46
|
functionIDs: Array<string>;
|
|
47
47
|
createdAt: string;
|
|
48
48
|
updatedAt: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devserver.d.ts","sourceRoot":"","sources":["../../src/helpers/devserver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG/C;;;;GAIG;AACH,
|
|
1
|
+
{"version":3,"file":"devserver.d.ts","sourceRoot":"","sources":["../../src/helpers/devserver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG/C;;;;GAIG;AACH,KAAK,MAAM,GAAG,OAAO,KAAK,CAAC;AAE3B;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,oCAUtB,MAAM,KACZ,QAAQ,OAAO,CASjB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,UACjB,MAAM,wBAEX,GAEF,CAAC;AAGF,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE;QACT,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;IAEF,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE;QACV,IAAI,EAAE,iBAAiB,CAAC;QACxB,IAAI,EAAE,iBAAiB,CAAC;KACzB,CAAC;IAEF,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,QAAQ,EAAE,UAAU,EAAE,CAAC;CACxB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,KAAK,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACb,CAAC,CAAC;CACJ,CAAC;AAEF,KAAK,UAAU,GAAG;IAChB,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACtB,GAAG,EAAE;QACH,GAAG,EAAE,MAAM,CAAC;QACZ,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH,CAAC"}
|
package/helpers/devserver.js
CHANGED
|
@@ -35,7 +35,7 @@ exports.devServerAvailable = devServerAvailable;
|
|
|
35
35
|
* Because Cloudflare/V8 platforms don't allow process.env, you are expected
|
|
36
36
|
* to pass in the host from the dev server env key:
|
|
37
37
|
*
|
|
38
|
-
* @example devServerUrl(
|
|
38
|
+
* @example devServerUrl(processEnv(envKeys.DevServerUrl), "/your-path")
|
|
39
39
|
* @example devServerUrl("http://localhost:8288/", "/your-path")
|
|
40
40
|
*/
|
|
41
41
|
const devServerUrl = (host = consts_1.defaultDevServerHost, pathname = "") => {
|
package/helpers/env.d.ts
CHANGED
|
@@ -8,10 +8,6 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export declare const devServerHost: () => string | undefined;
|
|
10
10
|
export declare const isProd: () => boolean;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* would mean we can drop `process.env` from everywhere in the codebase other
|
|
14
|
-
* than this function.
|
|
15
|
-
*/
|
|
16
|
-
export declare const hasProcessEnv: () => boolean;
|
|
11
|
+
export declare const processEnv: (key: string) => string | undefined;
|
|
12
|
+
export declare const allProcessEnv: () => Record<string, string | undefined>;
|
|
17
13
|
//# sourceMappingURL=env.d.ts.map
|
package/helpers/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/helpers/env.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,QAAO,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/helpers/env.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,QAAO,MAAM,GAAG,SAgBzC,CAAC;AAEF,eAAO,MAAM,MAAM,QAAO,OAQzB,CAAC;AAMF,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,MAAM,GAAG,SAEjD,CAAC;AAEF,eAAO,MAAM,aAAa,QAAO,OAAO,MAAM,EAAE,MAAM,GAAG,SAAS,CAOjE,CAAC"}
|