Comparing version 0.9.3-beta.1 to 0.9.3
@@ -51,3 +51,2 @@ "use strict"; | ||
url, | ||
signature: req.headers.get(consts_1.headerKeys.Signature) || undefined, | ||
}; | ||
@@ -54,0 +53,0 @@ } |
@@ -77,2 +77,7 @@ import type { PartialK, SendEventPayload, SingleOrArray } from "../helpers/types"; | ||
/** | ||
* Given a potential fetch function, return the fetch function to use based on | ||
* this and the environment. | ||
*/ | ||
private static parseFetch; | ||
/** | ||
* Set the event key for this instance of Inngest. This is useful if for some | ||
@@ -79,0 +84,0 @@ * reason the key is not available at time of instantiation or present in the |
@@ -89,4 +89,17 @@ "use strict"; | ||
}; | ||
this.fetch = Inngest.parseFetch(fetch); | ||
} | ||
/** | ||
* Given a potential fetch function, return the fetch function to use based on | ||
* this and the environment. | ||
*/ | ||
static parseFetch(fetchArg) { | ||
if (fetchArg) { | ||
return fetchArg; | ||
} | ||
if (typeof fetch !== "undefined") { | ||
return fetch; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
this.fetch = fetch || require("cross-fetch"); | ||
return require("cross-fetch"); | ||
} | ||
@@ -93,0 +106,0 @@ /** |
@@ -173,3 +173,2 @@ import type { MaybePromise } from "../helpers/types"; | ||
private readonly fns; | ||
private allowExpiredSignatures; | ||
constructor( | ||
@@ -314,3 +313,3 @@ /** | ||
protected shouldShowLandingPage(strEnvVar: string | undefined): boolean; | ||
protected validateSignature(sig: string | undefined, body: Record<string, any>): void; | ||
protected validateSignature(): boolean; | ||
protected signResponse(): string; | ||
@@ -376,3 +375,2 @@ } | ||
url: URL; | ||
signature: string | undefined; | ||
} | { | ||
@@ -379,0 +377,0 @@ action: "bad-method"; |
@@ -5,2 +5,3 @@ "use strict"; | ||
const hash_js_1 = require("hash.js"); | ||
const serialize_error_cjs_1 = require("serialize-error-cjs"); | ||
const zod_1 = require("zod"); | ||
@@ -131,3 +132,2 @@ const consts_1 = require("../helpers/consts"); | ||
transformRes) { | ||
var _a; | ||
/** | ||
@@ -152,9 +152,2 @@ * A property that can be set to indicate whether or not we believe we are in | ||
this.transformRes = transformRes; | ||
/** | ||
* Provide a hidden option to allow expired signatures to be accepted during | ||
* testing. | ||
*/ | ||
this.allowExpiredSignatures = Boolean( | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, prefer-rest-params | ||
(_a = arguments["3"]) === null || _a === void 0 ? void 0 : _a.__testingAllowExpiredSignatures); | ||
this.fns = functions.reduce((acc, fn) => { | ||
@@ -247,5 +240,3 @@ const id = fn.id(this.name); | ||
if (runRes) { | ||
this._isProd = runRes.isProduction; | ||
this.upsertSigningKeyFromEnv(runRes.env); | ||
this.validateSignature(runRes.signature, runRes.data); | ||
const stepRes = await this.runStep(runRes.fnId, "step", runRes.data); | ||
@@ -267,3 +258,2 @@ if (stepRes.status === 500 || stepRes.status === 400) { | ||
if (viewRes) { | ||
this._isProd = viewRes.isProduction; | ||
this.upsertSigningKeyFromEnv(viewRes.env); | ||
@@ -294,3 +284,2 @@ const showLandingPage = this.shouldShowLandingPage(viewRes.env[consts_1.envKeys.LandingPage]); | ||
if (registerRes) { | ||
this._isProd = registerRes.isProduction; | ||
this.upsertSigningKeyFromEnv(registerRes.env); | ||
@@ -308,4 +297,3 @@ const { status, message } = await this.register(this.reqUrl(registerRes.url), registerRes.env[consts_1.envKeys.DevServerUrl], registerRes.deployId); | ||
status: 500, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
body: JSON.stringify(err.stack || err.message || err), | ||
body: JSON.stringify(Object.assign({ type: "internal" }, (0, serialize_error_cjs_1.serializeError)(err))), | ||
headers: Object.assign(Object.assign({}, headers), { "Content-Type": "application/json" }), | ||
@@ -345,4 +333,12 @@ }; | ||
} | ||
catch (err) { | ||
catch (unserializedErr) { | ||
/** | ||
* Always serialize the error before sending it back to Inngest. Errors, | ||
* by default, do not niceley serialize to JSON, so we use the a package | ||
* to do this. | ||
* | ||
* See {@link https://www.npmjs.com/package/serialize-error} | ||
*/ | ||
const error = JSON.stringify((0, serialize_error_cjs_1.serializeError)(unserializedErr)); | ||
/** | ||
* If we've caught a non-retriable error, we'll return a 400 to Inngest | ||
@@ -354,26 +350,5 @@ * to indicate that the error is not transient and should not be retried. | ||
*/ | ||
if (err instanceof NonRetriableError_1.NonRetriableError) { | ||
return { | ||
status: 400, | ||
error: JSON.stringify({ | ||
message: err.message, | ||
stack: err.stack, | ||
name: err.name, | ||
cause: err.cause | ||
? err.cause instanceof Error | ||
? err.cause.stack || err.cause.message | ||
: JSON.stringify(err.cause) | ||
: undefined, | ||
}), | ||
}; | ||
} | ||
if (err instanceof Error) { | ||
return { | ||
status: 500, | ||
error: err.stack || err.message, | ||
}; | ||
} | ||
return { | ||
status: 500, | ||
error: `Unknown error: ${JSON.stringify(err)}`, | ||
status: unserializedErr instanceof NonRetriableError_1.NonRetriableError ? 400 : 500, | ||
error, | ||
}; | ||
@@ -488,22 +463,4 @@ } | ||
} | ||
validateSignature(sig, body) { | ||
if (this.isProd && !sig) { | ||
throw new Error(`No ${consts_1.headerKeys.Signature} provided`); | ||
} | ||
if (!this.isProd && !this.signingKey) { | ||
return; | ||
} | ||
if (!this.signingKey) { | ||
console.warn("No signing key provided to validate signature. Find your dev keys at https://app.inngest.com/test/secrets"); | ||
return; | ||
} | ||
if (!sig) { | ||
console.warn(`No ${consts_1.headerKeys.Signature} provided`); | ||
return; | ||
} | ||
new RequestSignature(sig).verifySignature({ | ||
body, | ||
allowExpiredSignatures: this.allowExpiredSignatures, | ||
signingKey: this.signingKey, | ||
}); | ||
validateSignature() { | ||
return true; | ||
} | ||
@@ -515,36 +472,2 @@ signResponse() { | ||
exports.InngestCommHandler = InngestCommHandler; | ||
class RequestSignature { | ||
constructor(sig) { | ||
const params = new URLSearchParams(sig); | ||
this.timestamp = params.get("t") || ""; | ||
this.signature = params.get("s") || ""; | ||
if (!this.timestamp || !this.signature) { | ||
throw new Error(`Invalid ${consts_1.headerKeys.Signature} provided`); | ||
} | ||
} | ||
hasExpired(allowExpiredSignatures) { | ||
if (allowExpiredSignatures) { | ||
return false; | ||
} | ||
const delta = Date.now() - new Date(parseInt(this.timestamp) * 1000).valueOf(); | ||
return delta > 1000 * 60 * 5; | ||
} | ||
verifySignature({ body, signingKey, allowExpiredSignatures, }) { | ||
if (this.hasExpired(allowExpiredSignatures)) { | ||
throw new Error("Signature has expired"); | ||
} | ||
// Calculate the HMAC of the request body ourselves. | ||
const encoded = typeof body === "string" ? body : JSON.stringify(body); | ||
// Remove the /signkey-[test|prod]-/ prefix from our signing key to calculate the HMAC. | ||
const key = signingKey.replace(/signkey-\w+-/, ""); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
const mac = (0, hash_js_1.hmac)(hash_js_1.sha256, key) | ||
.update(encoded) | ||
.update(this.timestamp) | ||
.digest("hex"); | ||
if (mac !== this.signature) { | ||
throw new Error("Invalid signature"); | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=InngestCommHandler.js.map |
@@ -35,3 +35,2 @@ "use strict"; | ||
isProduction, | ||
signature: req.headers.get(consts_1.headerKeys.Signature) || undefined, | ||
}; | ||
@@ -38,0 +37,0 @@ } |
import type { ServeHandler } from "./components/InngestCommHandler"; | ||
type HTTP = { | ||
headers: Record<string, string>; | ||
headers: { | ||
host?: string; | ||
}; | ||
method: string; | ||
@@ -5,0 +7,0 @@ path: string; |
@@ -54,3 +54,2 @@ "use strict"; | ||
url, | ||
signature: http.headers[consts_1.headerKeys.Signature], | ||
}; | ||
@@ -57,0 +56,0 @@ } |
@@ -29,3 +29,2 @@ "use strict"; | ||
url, | ||
signature: req.headers[consts_1.headerKeys.Signature], | ||
}; | ||
@@ -32,0 +31,0 @@ } |
@@ -18,6 +18,3 @@ export declare enum queryKeys { | ||
} | ||
export declare enum headerKeys { | ||
Signature = "x-inngest-signature" | ||
} | ||
export declare const defaultDevServerHost = "http://127.0.0.1:8288/"; | ||
//# sourceMappingURL=consts.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultDevServerHost = exports.headerKeys = exports.prodEnvKeys = exports.envKeys = exports.queryKeys = void 0; | ||
exports.defaultDevServerHost = exports.prodEnvKeys = exports.envKeys = exports.queryKeys = void 0; | ||
var queryKeys; | ||
@@ -24,7 +24,3 @@ (function (queryKeys) { | ||
})(prodEnvKeys = exports.prodEnvKeys || (exports.prodEnvKeys = {})); | ||
var headerKeys; | ||
(function (headerKeys) { | ||
headerKeys["Signature"] = "x-inngest-signature"; | ||
})(headerKeys = exports.headerKeys || (exports.headerKeys = {})); | ||
exports.defaultDevServerHost = "http://127.0.0.1:8288/"; | ||
//# sourceMappingURL=consts.js.map |
@@ -41,3 +41,2 @@ "use strict"; | ||
url, | ||
signature: req.headers[consts_1.headerKeys.Signature], | ||
}; | ||
@@ -44,0 +43,0 @@ } |
{ | ||
"name": "inngest", | ||
"version": "0.9.3-beta.1", | ||
"version": "0.9.3", | ||
"description": "Official SDK for Inngest.com", | ||
@@ -56,4 +56,6 @@ "main": "./index.js", | ||
"cross-fetch": "^3.1.5", | ||
"h3": "^1.0.2", | ||
"hash.js": "^1.1.7", | ||
"ms": "^2.1.3", | ||
"serialize-error-cjs": "^0.1.3", | ||
"sigmund": "^1.0.1", | ||
@@ -60,0 +62,0 @@ "type-fest": "^3.5.1", |
@@ -51,3 +51,2 @@ "use strict"; | ||
fnId: (_a = event.queryStringParameters) === null || _a === void 0 ? void 0 : _a[consts_1.queryKeys.FnId], | ||
signature: event.headers[consts_1.headerKeys.Signature], | ||
}; | ||
@@ -54,0 +53,0 @@ } |
@@ -55,3 +55,2 @@ "use strict"; | ||
url, | ||
signature: req.headers.get(consts_1.headerKeys.Signature) || undefined, | ||
}; | ||
@@ -58,0 +57,0 @@ } |
@@ -1,2 +0,2 @@ | ||
export declare const version = "0.9.3-beta.1"; | ||
export declare const version = "0.9.3"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
// Generated by genversion. | ||
exports.version = "0.9.3-beta.1"; | ||
exports.version = "0.9.3"; | ||
//# sourceMappingURL=version.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
103
4379
398303
9
7
+ Addedh3@^1.0.2
+ Addedserialize-error-cjs@^0.1.3
+ Addedcookie-es@1.2.2(transitive)
+ Addedcrossws@0.3.4(transitive)
+ Addeddefu@6.1.4(transitive)
+ Addeddestr@2.0.3(transitive)
+ Addedh3@1.15.0(transitive)
+ Addediron-webcrypto@1.2.1(transitive)
+ Addednode-mock-http@1.0.0(transitive)
+ Addedohash@1.1.4(transitive)
+ Addedradix3@1.1.2(transitive)
+ Addedserialize-error-cjs@0.1.4(transitive)
+ Addedufo@1.5.4(transitive)
+ Addeduncrypto@0.1.3(transitive)